Question

Autocad 2007 VBA-Draw order in a Block

Asked by: norrin_radd

I'm trying to make sure my wipeouts are set behind everything in my blocks. I'm going to eventually work this into happening on insert but for now I'd just like to get it to happen at all by selecting the block.
I've figured out how to use the AcDbSortentsTable to move objects behind in modelspace, I cant get it to work in a block. This code is a combination of updateing a block and moving objects behind from the help files look up "sortentstable example" for that example.
I want to try to avoid having to explode the block and put it back together if I can, not sure if that will work anyway.

Just for reference, this first code is the basic editing a block that works(got it from autodesk's ng):
*********************
Public Sub UpdateBlockDefinition()
Dim Entity As AcadEntity
Dim BlockEntity As AcadEntity
Dim BlockDefinition As AcadBlock
Dim BlockReference As AcadBlockReference
Dim SelectionSet As AcadSelectionSet

On Error Resume Next
ThisDrawing.SelectionSets.Item("BlockToUpdate").Delete
On Error GoTo 0

Set SelectionSet = ThisDrawing.SelectionSets.Add("BlockToUpdate")
SelectionSet.SelectOnScreen

For Each Entity In SelectionSet
If TypeOf Entity Is AcadBlockReference Then
Set BlockReference = Entity
For Each BlockDefinition In ThisDrawing.Blocks
If BlockDefinition.Name = BlockReference.Name Then
For Each BlockEntity In BlockDefinition
' Do your modifications here...
BlockEntity.color = acRed
BlockEntity.Layer = "0"
BlockEntity.Update
Next BlockEntity
End If
Next BlockDefinition
End If
Next Entity
End Sub
*****************
This is the code I pieced together with the above and the sortentstable from the help files.

*******************
Public Sub UpdateBlockDefinition()
Dim Entity As AcadEntity
Dim BlockEntity As AcadEntity
Dim BlockDefinition As AcadBlock
Dim BlockReference As AcadBlockReference
Dim SelectionSet As AcadSelectionSet

'Get an extension dictionary and, if necessary, add a SortentsTable object
    Dim eDictionary As Object
    Set eDictionary = ThisDrawing.ModelSpace.GetExtensionDictionary
    ' Prevent failed GetObject calls from throwing an exception
    On Error Resume Next
    Dim sentityObj As Object
    Set sentityObj = eDictionary.GetObject("ACAD_SORTENTS")
   
    On Error GoTo 0
    If sentityObj Is Nothing Then
         ' No SortentsTable object, so add one
         Set sentityObj = eDictionary.AddObject("ACAD_SORTENTS", "AcDbSortentsTable")
    End If

On Error Resume Next
ThisDrawing.SelectionSets.Item("BlockToUpdate").Delete
On Error GoTo 0

Set SelectionSet = ThisDrawing.SelectionSets.Add("BlockToUpdate")
SelectionSet.SelectOnScreen

   
For Each Entity In SelectionSet
If TypeOf Entity Is AcadBlockReference Then


Set BlockReference = Entity

For Each BlockDefinition In ThisDrawing.Blocks

   
If BlockDefinition.NAME = BlockReference.NAME Then
     
       
For Each BlockEntity In BlockDefinition
' Do your modifications here...

'MsgBox BlockEntity.ObjectName
If BlockEntity.ObjectName = "AcDbWipeout" Then
'MsgBox "wipeout"

     Dim ObjIds(0) As Long
     ObjIds(0) = BlockEntity.ObjectID
     'ObjIds(1) = leaderObj.ObjectID
     Dim varObject As ACADObject
     Set varObject = ThisDrawing.ObjectIdToObject(ObjIds(0))
     Dim arr(0) As ACADObject
     Set arr(0) = varObject

    'MsgBox arr(0).ObjectName

    'Move the object to the bottom
    sentityObj.MoveToBottom arr '**** I get an invalid input error here.
     AcadApplication.Update

End If

Next BlockEntity
End If
Next BlockDefinition
End If
Next Entity
End Sub
*******************

Any help/suggestions would be appreciated.



dragontooth, you did see that DT(bat) signal in the sky last night didnt ya? ;)
http://upload.wikimedia.org/wikipedia/en/a/ad/Bat-signalBatman_1989.jpg

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-09-14 at 07:28:43ID21989469
Tags

autocad

,

vba

,

block

Topic

CAD & Architecture Software

Participating Experts
2
Points
500
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ACAD into Delphi ??
    I need to capture ACAD's dwg file into Delphi application in the way that I can get informations about lines in it discribed with points x y and z. Is there a program which can transform dwg or other (ACAD export) kind of file into something I could use; or maybe someone can ...
  2. Autodesk Autocad automatic computer performance test
    Does anyone know of a way to run a performance test on a PC that gauges its ACAD performance? Maybe VBA code that makes ACAD itself run the test, or a third party software. I am running ACAD Map2004, and I am interested in rating my PC's and generating minimum requirements d...
  3. How to run VBA in AutoCAD alone.
    OK. You're probably going to think that this is stupid question but believe me I have a good reason for asking this. My IT Manager waited so long to give me AutoCAD that had a VBA editor that I had develop all kinds of stuff through Access 97 VBA to do what I wanted AutoCAD...
  4. Urgent!!! Autocad VBA copy to clipboard
    Hi All I am in need of some help very quickly to finish a job I am using autocad 2002 and pdf995 to generate pdf files I have constructed a VBA program to copy the drawing name to the clipboard since the saving name in pdf995 is malformed The program sucessfully copyies t...
  5. AutoCAD LT 2007 usage via OLE Automation
    Hi! I have installed AutoCAD 2007 LT and I am trying to automate it by means of OLE in MS Visual Basic 6, but it is failing. Creation of the AutoCAD.Application instance fails. Set m_aaApp = CreateObject("AutoCAD.Application.17") It hangs during one, two minutes ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: dragontoothPosted on 2006-09-14 at 13:42:01ID: 17524244

LOL no and I was looking hehe, the version I have is 2000i and after seaching the autodesk ng (I hang out there on occasion also as dragontooth don't post much because of the version - "they" are already on 2007) I find that I require at least 2005 for this. So if you can give me an explaination of "wipeouts are set behind everything in my blocks" I'll see what I can do. I "may" be able to get access. My understanding is you can run different versions side by side. Could you post a drawing with the information? There is a website around that Netminder and andother mod is sponsering but I don't know the link, otherwise e-mail is in profile.

I think you are talking about the "z" order, or the order in which each object was created in the block. One method could be to redefine the block or just rewrite it, in code it would be a lot faster but as you said really don't want to go there.

I'll look into it when I get home, but for now don't you have to add items to the sentityObj object before doing anything with them?

I'll post back when I know what I'm talking/doing LOL
dragontooth

 

by: norrin_raddPosted on 2006-09-14 at 14:16:25ID: 17524499

alright, are you also an augi member? I posted same question over there to see what they could come up with, I could attach a file there.

what I meant by  "wipeouts are set behind everything in my blocks" is this. Sometimes when I insert a block into a dwg that has a wipeout in it, the wipeout is brought to the front in the block reference. To fix this I have to either refedit the block and put the wipeout to the back, I used to do this with the ai_draworder command, not sure if it was available back in 2000i. or open it with the new blockeditor now and set it to the back with the new draworder command (not sure if there's any difference actually but they added it to the rightclick popup)
I have attempted everyway possible to fix this with out code but have gotten no where. it doesnt happen as much in 2007 but it still does occasionally.
The zorder may be a way but I dont know.

<but for now don't you have to add items to the sentityObj object before doing anything with them?>
thats what I thought this bit does:
'********
Dim ObjIds(0) As Long
     ObjIds(0) = BlockEntity.ObjectID
     'ObjIds(1) = leaderObj.ObjectID
     Dim varObject As ACADObject
     Set varObject = ThisDrawing.ObjectIdToObject(ObjIds(0))
     Dim arr(0) As ACADObject
     Set arr(0) = varObject

    'MsgBox arr(0).ObjectName

    'Move the object to the bottom
    sentityObj.MoveToBottom arr '**** I get an invalid input error here.
     AcadApplication.Update
'***********
It works when I use this in another piece of code that inserts a block, creates a leader attaches the block to the leader then sets the leader behind the block. I'll put that code in the dwg I post too. But it doesnt work while I'm "inside" the block reference.
I'm probably going about this all wrong but it was worth a shot. Let me know if you can get on augi forums and I'll post a link, its free too, if you need another forum to subscribe too ;)

 

by: dragontoothPosted on 2006-09-14 at 16:44:24ID: 17525359

WOW big change for 2005

I found auig and the thread

hehe busy

 

by: dragontoothPosted on 2006-09-15 at 09:19:36ID: 17530641

I'm on aiug now, <But it doesnt work while I'm "inside" the block reference> I don't think it's going to. You are in a block reference not the block. I am thinking you would need to grab the block work it and then update the reference. The reason I am thinking this is because you can have 1 block and 60 references to that block. The only differences being the attributes, and what layer the block was inserted on.

I will look into this this weekend and see what I can come up with, I am thinking right now that we would need to reorganize/reorder the block.

Just updating
dragontooth

 

by: norrin_raddPosted on 2006-09-15 at 09:41:43ID: 17530793

ah that makes sense, I'll tinker with that too
thanks

 

by: norrin_raddPosted on 2006-09-15 at 12:00:39ID: 17531823

I think I got it, and I think you were totally correct dt. I had to create the dictionary "inside" the block not the reference, check it:

'**********
Sub wipeoutsInBlock()
   
    ' Create the block, this is done even if the block is already in the dwg
    Dim blockObj As AcadBlock
    Dim insertionPnt(0 To 2) As Double
    insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
    Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "XING_DET_B")
   
   
   
'Gxet an extension dictionary and, if necessary, add a SortentsTable object**this is done "inside" the block.
    Dim eDictionary As Object
    Set eDictionary = blockObj.GetExtensionDictionary '***this was the key
    ' Prevent failed GetObject calls from throwing an exception
    On Error Resume Next
    Dim sentityObj As Object
    Set sentityObj = eDictionary.GetObject("ACAD_SORTENTS")
   
    On Error GoTo 0
    If sentityObj Is Nothing Then
         ' No SortentsTable object, so add one
         Set sentityObj = eDictionary.AddObject("ACAD_SORTENTS", "AcDbSortentsTable")
    End If
   
    Dim ents As AcadEntity
    For Each ents In blockObj
    If ents.ObjectName = "AcDbWipeout" Then

     Dim ObjIds(0) As Long
    ObjIds(0) = ents.ObjectID
   
     Dim varObject As ACADObject
    Set varObject = ThisDrawing.ObjectIdToObject(ObjIds(0))
    Dim arr(0) As ACADObject
    Set arr(0) = varObject
   
    'Move the wipeout object to the bottom
    sentityObj.MoveToBottom arr
         
    'MsgBox ents.ObjectName
    End If
    Next
    ThisDrawing.Regen acAllViewports
     
End Sub
 ' *********

what do you think? it seems to work.

 

by: dragontoothPosted on 2006-09-15 at 12:21:44ID: 17531994

Well that looks like it makes sense. The only thing that bugs me is what if the block exists would you still want to use .add? or wouldn't you want to set it = to the existing one? as in ThisDrawing.Blocks( "XING_DET_B") it accomplishes the same thing just clearer. But I haven't tested or tried at this point. Oh don't forget to clear the err object, just in case it throws an error. Otherwise it will show up someplace else and drive you crazy trying to find it. LOL

I'll look at it in 2005 at home with some drawing so I will know what I'm talking about, I tried here and it flipped out 2000i hehe funny till I had to clean up the mess I made.

Later
dragontooth



 

by: norrin_raddPosted on 2006-09-15 at 12:34:06ID: 17532084

you're right I changed it to ThisDrawing.Blocks( "XING_DET_B")   and it works too, and clearer, the other was a hold over from the help file example code, doh!
added the err.clear too,

hope you didnt screw up 2000i too bad ;)

this bug has been buggin me since they created wipeouts, r14 I think, feels good to be close to squashin it!

thanks for your help.
have a good weekend.

 

by: dragontoothPosted on 2006-09-17 at 13:30:44ID: 17539459

Nope not too bad anyway :) I have all my custom files on a cd just a copy and start. :)

I tested the last sub you posted and like it a lot. I looked and cleaned it up a little shorten it a little and set it up to run on all blocks that are inserted in the drawing. You could fire this sub on a AcadDocument_BeginSave event, that way the next time the doc is open it looks right or whatever, you get what I'm saying.

Sub wipeoutsInBlock()
    Dim blockObj As AcadBlock
    Dim eDictionary As AcadDictionary
    Dim sentityObj As Object
    Dim ents As AcadEntity
    Dim arr(0) As ACADObject
    For Each blockObj In ThisDrawing.Blocks
        'Gxet an extension dictionary and, if necessary, add a SortentsTable object**this is done "inside" the block.
        Set eDictionary = blockObj.GetExtensionDictionary '***this was the key
        ' Prevent failed GetObject calls from throwing an exception
        On Error Resume Next
        Set sentityObj = eDictionary.GetObject("ACAD_SORTENTS")
        If Err.Number <> 0 Then
            If sentityObj Is Nothing Then
                ' No SortentsTable object, so add one
                Set sentityObj = eDictionary.AddObject("ACAD_SORTENTS", "AcDbSortentsTable")
            End If
            Err.Clear   '   just a way to get error numbers if/when they occur
        End If
        On Error GoTo 0
        For Each ents In blockObj
            If ents.ObjectName = "AcDbWipeout" Then
                Set arr(0) = ThisDrawing.ObjectIdToObject(ents.ObjectID)
                'Move the wipeout object to the bottom
                sentityObj.MoveToBottom arr
                'MsgBox ents.ObjectName
            End If
        Next
    Next
    ThisDrawing.Regen acAllViewports
    'clean up anything that may be left over
    Set sentityObj = Nothing
    Set eDictionary = Nothing
    Set blockObj = Nothing
    Set ents = Nothing
End Sub

dragontooth

 

by: norrin_raddPosted on 2006-09-18 at 10:02:33ID: 17545040

thanks again dt, this is what I went for now, using it to call from another module:

'********
Public Sub WToF_InBlock(bname As String)
    Dim blockObj As AcadBlock
    Dim eDictionary As AcadDictionary
    Dim sentityObj As Object
    Dim ents As AcadEntity
    Dim arr(0) As ACADObject
    'For Each blockObj In ThisDrawing.Blocks
    Set blockObj = ThisDrawing.Blocks(bname)
        'Gxet an extension dictionary and, if necessary, add a SortentsTable object**this is done "inside" the block.
        Set eDictionary = blockObj.GetExtensionDictionary '***this was the key
        ' Prevent failed GetObject calls from throwing an exception
        On Error Resume Next
        Set sentityObj = eDictionary.GetObject("ACAD_SORTENTS")
        If Err.Number <> 0 Then
            If sentityObj Is Nothing Then
                ' No SortentsTable object, so add one
                Set sentityObj = eDictionary.AddObject("ACAD_SORTENTS", "AcDbSortentsTable")
            End If
            Err.Clear   '   just a way to get error numbers if/when they occur
        End If
        On Error GoTo 0
        For Each ents In blockObj
            If ents.ObjectName = "AcDbWipeout" Then
                Set arr(0) = ThisDrawing.ObjectIdToObject(ents.ObjectID)
                'Move the wipeout object to the bottom
                sentityObj.MoveToBottom arr
                'MsgBox ents.ObjectName
            End If
        Next
'    Next
    ThisDrawing.Regen acActiveViewport
    'clean up anything that may be left over
    Set sentityObj = Nothing
    Set eDictionary = Nothing
    Set blockObj = Nothing
    Set ents = Nothing
End Sub
'***********

I'll probably is this in a few different ways, I like the idea of the begin_save event.
thanks

 

by: daviperPosted on 2008-02-15 at 10:47:50ID: 20904690

I have not had any luck getting this to work.  I get an error on this line

sentityObj.MoveToBottom arr

But I am using Civil3D 2008 not 2007 if this could be the issue?  I get an invalid input kicked back pretty quickly.

 

by: daviperPosted on 2008-02-15 at 11:43:31ID: 20905213

Also, this code moves all the wipeouts to the back but only wipeouts not contained within a block.

 

by: dragontoothPosted on 2008-02-15 at 13:33:04ID: 20906178

You will need to iterate through the entities in the blocks to get to the wipeout.

 

by: daviperPosted on 2008-02-15 at 13:54:57ID: 20906388

I took your code exactly except i put it into a CMD button..

But does this not iterate thru?

        For Each ents In blockObj
            If ents.ObjectName = "AcDbWipeout" Then
                Set arr(0) = ThisDrawing.ObjectIdToObject(ents.ObjectID)
                'Move the wipeout object to the bottom
                sentityObj.MoveToBottom arr
                'MsgBox ents.ObjectName
            End If
        Next

 

by: daviperPosted on 2008-02-15 at 13:57:17ID: 20906407

IF there is some way I can do this and award points (am still learning experts exchange)

 

by: daviperPosted on 2008-02-15 at 14:06:31ID: 20906479

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...