![]() |
|
|
#1 |
|
|
AutoCAD VBA - Change all objects to Lay 0
Hey Guys,
Would anyone have VBA code example that would allow me to change all the drawing objects from their current layers to layer 0 ? I have code now that automatically scans a dir. of cad files and makes other changes but I just need to add this. Thanks for any help with this! |
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#2 |
|
Moderator
|
This will work for most things but I can't say if it will work correct with block entities.
VBA:
VBA tags courtesy of www.thecodenet.com
|
|
Local Time: 10:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#3 |
|
|
Hi Tommy,
The code is running but does not seem to be doing anything. Does this add a layer or does it put "ALLEntities" on layer 0 ? Am I supposed to make any changes to it first? Thanks, Rob |
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#4 |
|
Moderator
|
Hey Rob,
How are you calling the sub? Like ChnageAllToLyer "0" ? Oh well this will end the confusion Sorry VBA:
VBA tags courtesy of www.thecodenet.com
|
|
Local Time: 10:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#5 |
|
|
Well I am pasting it directly into my program just as you posted it. I just tried this new one as it is, and again it does run (thats a good thing) but nothing changes. I am trying to think what I may need to do......
|
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#6 |
|
Moderator
|
Please post the dwg in a zip file so I can figure out what is wrong.
Thanks |
|
Local Time: 10:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#7 | |||||||||||||||||||||||
|
|
Tommy I can't send the actual drawing BUT here is the VBA Code, scroll all the way down to the bottom to see it. I am using 2005, and this is being implemented automatically without an actual drawing being open, just AutoCAD. VBA:
VBA tags courtesy of www.thecodenet.com
|
|||||||||||||||||||||||
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#8 |
|
Moderator
|
Hey Rob,
Who says you can't teach an old dog new tricks. I had the same problem and didn't know it!! This fixed it though ![]() VBA:
VBA tags courtesy of www.thecodenet.com
|
|
Local Time: 10:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#9 |
|
|
Hey Tommy,
I included a zip file of a rectangle. Take a look at it please, because I was not able to change my objects (rectangle) to layer 0 so maybe its my Cad system not sure. One other thing I use 2005 BUT I have to save as a 2000 for our vendor. Thanks for the help |
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#10 |
|
Moderator
|
I changed the version to acad 2000 cause I don't have the particular version you have/was posted. I then ran the macro(revised already posted). It worked.
The new file name is testab.dxfEDIT: Added the name of the new dxf |
|
Local Time: 10:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#11 |
|
|
Hi, guys
Just have thought, perhaps, there is need to add the piece of code to work with locked layers... Something like: Code:
Bear in mind this will not change the layer of subentities, say in blocks and also the same thing with other complex objects like the dimensions, leaders etc. Regards, Oleg ~'J'~ |
|
Local Time: 08:00 AM
Local Date: 09-03-2010 Location:
|
|
|
|
#12 | |||||||||||||||||||||||
|
|
I look at the file and yeah it did work for you........so I have some strange setting problably screwing me up somewhere.......ok I will have to look into this more. Thanks alot guys! |
|||||||||||||||||||||||
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#13 |
|
|
Hey Folks
Hope you dom't mind me butting in on your discussion. I have a similar problem. I have a messy drawing with entities scattered over lots of different layers (a survey drawing with GPS points etc). I am trying to move all the entities onto certain layers depending on what the object name is and possibly on its colour. I was having trouble with my code finding all of the different objectnames so I tried tried your code and it really blew up. On the line "Set ssAll = ThisDrawing.SelectionSets.Add("AllEntities")" it gives an error message "The named selection set exists". I am using version 2007. Any clues? The code I was trying to use is listed below. VBA:
VBA tags courtesy of www.thecodenet.com
The array bit is only there to get a distinct list of objectnames. The problem I am having is that it only finds three objectnames. AcDbCircle AcDbPoint AcDbText I know that I have ordinary lines, splines and polylines but it just won't find then. Any help would be very much appreciated. Thanks EDIT: Added VBA tags Tommy |
|
Local Time: 02:00 PM
Local Date: 09-03-2010 Location:
|
|
|
|
#14 |
|
|
Hey don't mind me!!
I was just looking through my code and realise that I didn't reset 'xBool' to false so it couldn't print all the names. It now happily finds my lines and polylines etc etc. I also realised that i needed to delete the SelectionSet in your code before rsetting it so it works happily as well. Thank again |
|
Local Time: 02:00 PM
Local Date: 09-03-2010 Location:
|
|
|
|
#15 |
|
|
Educate me, what is SelectionSet all about, because I have no idea? I use AutoCAD all the time but I am new to VB and the programing world.
Rob |
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#16 |
|
Moderator
|
A selectionset is just another way to select a group of entities. The entities could be in a layer, multiple layers, just one type of entity. You can filter the selection set with dxf codes. Once the selection set is filled or has entities you can iterate through it and modify (change layers, colors, linetype....)
The selection set problem should have been taken care of here (as originally posted by Fatty )VBA:
VBA tags courtesy of www.thecodenet.com
See this post for more information and how to filter .. well at least a small discussion on it. http://www.vbaexpress.com/forum/showthread.php?t=7479 @ DennisHowe Why don't you filter the selection set? |
|
Local Time: 10:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#17 |
|
|
Changing Multiple Layer Colors
Is it possible to modify the code used in this thread to select all the layers in a drawing and set their color to white? I am a field engineer and I am creating my "as built" drawings electronically. In order to clearly identify what I need changed I want to convert all existing layers to white. Would someone be so kind as to help get me pointed in the right direction. I have some VBA experience with Excel, but I'm new to AutoCAD.
Thanks, Spike |
|
Local Time: 10:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#18 |
|
|
Here is a quick and dirty solution, based on I posted
above, unfortunately I haven't have a time to varnish this code Anyway, you can try it Code:
~'J'~ |
|
Local Time: 08:00 AM
Local Date: 09-03-2010 Location:
|
|
|
|
#19 |
|
Administrator
|
Spike, you really should start a new thread to ask this question as it's not closely related to what they are doing here.
Your problem is not that hard to resolve. Steve ![]() "Nearly all men can stand adversity, but if you want to test a man's character, give him power." -Abraham Lincoln |
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
|
|
#20 |
|
Administrator
|
Please excuse my intrusion. I thought I was on the stretching diminsions thread.......carry on as if I was never here.
Steve ![]() "Nearly all men can stand adversity, but if you want to test a man's character, give him power." -Abraham Lincoln |
|
Local Time: 11:00 PM
Local Date: 09-02-2010 Location:
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Debt Help | PT Cruiser | Motorhome Insurance | Find jobs | Debt Help