Jump to content

Layerstate applied via lisp?


jtk07

Recommended Posts

Ok what I am trying to make is a lisp file that would be able to be run to load a saved .las (layer state) file and set it as current. Anyone have any thoughts on this? I know i can manually do each file one at a time however I have over 170 files and this would take forever I just don't know what the command line would look like. If anyone can help me write this i think it would really make layerstate automation great for everyone. Set it to run at night or on an empty workstation and come in in the morning and your done seems useful to me.

 

Any help would be appreciated

 

JTK

Link to comment
Share on other sites

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • jtk07

    12

  • irneb

    6

  • alanjt

    5

  • jeinbinder

    4

Top Posters In This Topic

Posted Images

Try the layerstate-* commands.

 

Straight from Help:

[list]
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67f2.htm"]layerstate-addlayers[/url]  
Adds or updates a  series of layers to a layer state
[*][url="http://www.cadtutor.net/forum/WS73099cc142f487551ec84dc1111af5a7b7-7c9c.htm"]layerstate-compare[/url]  
Compares a layerstate  to the layers in the current drawing
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67df.htm"]layerstate-delete[/url]  
Deletes a layer  state
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67bd.htm"]layerstate-export[/url]  
Exports a layer state  to a specified file
[*][url="http://www.cadtutor.net/forum/WS73099cc142f487551ec84dc1111af5a7b7-7c8f.htm"]layerstate-getlastrestored[/url]  
Returns the  name of the last restored layer state in the current drawing
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67ca.htm"]layerstate-getlayers[/url]  
Returns the layers  saved in a layer state
[*][url="http://www.cadtutor.net/forum/WS73099cc142f487551ec84dc1111af5a7b7-7c8a.htm"]layerstate-getnames[/url]  
Returns a list of the  layer state names
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67e5.htm"]layerstate-has[/url]  
Checks if a layer state is  present
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67c3.htm"]layerstate-import[/url]  
Imports a layer state  from a specified file
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ff1b508da11142adfd67-7f9c.htm"]layerstate-importfromdb[/url]  
Imports a layer  state from a specified drawing file
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ff1b508da11142adfd67-7f94.htm"]layerstate-removelayers[/url]  
Removes a list of  layers from a layer state
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67d9.htm"]layerstate-rename[/url]  
Renames a layer  state
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67b6.htm"]layerstate-restore[/url]  
Restores a layer state  into the current drawing
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67d2.htm"]layerstate-save[/url]  
Saves a layer state in  the current drawing
[/list]

Link to comment
Share on other sites

And this is what i get and continue to get

"Command: layerstate-importfromdb

Unknown command "LAYERSTATE-IMPORTFROMDB". Press F1 for help."

 

Try the layerstate-* commands.

 

Straight from Help:


[list]
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67f2.htm"]layerstate-addlayers[/url]  
Adds or updates a  series of layers to a layer state
[*][url="http://www.cadtutor.net/forum/WS73099cc142f487551ec84dc1111af5a7b7-7c9c.htm"]layerstate-compare[/url]  
Compares a layerstate  to the layers in the current drawing
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67df.htm"]layerstate-delete[/url]  
Deletes a layer  state
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67bd.htm"]layerstate-export[/url]  
Exports a layer state  to a specified file
[*][url="http://www.cadtutor.net/forum/WS73099cc142f487551ec84dc1111af5a7b7-7c8f.htm"]layerstate-getlastrestored[/url]  
Returns the  name of the last restored layer state in the current drawing
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67ca.htm"]layerstate-getlayers[/url]  
Returns the layers  saved in a layer state
[*][url="http://www.cadtutor.net/forum/WS73099cc142f487551ec84dc1111af5a7b7-7c8a.htm"]layerstate-getnames[/url]  
Returns a list of the  layer state names
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67e5.htm"]layerstate-has[/url]  
Checks if a layer state is  present
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67c3.htm"]layerstate-import[/url]  
Imports a layer state  from a specified file
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ff1b508da11142adfd67-7f9c.htm"]layerstate-importfromdb[/url]  
Imports a layer  state from a specified drawing file
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ff1b508da11142adfd67-7f94.htm"]layerstate-removelayers[/url]  
Removes a list of  layers from a layer state
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67d9.htm"]layerstate-rename[/url]  
Renames a layer  state
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67b6.htm"]layerstate-restore[/url]  
Restores a layer state  into the current drawing
[*][url="http://www.cadtutor.net/forum/WS1a9193826455f5ffd9a7a610ecb0483d5-67d2.htm"]layerstate-save[/url]  
Saves a layer state in  the current drawing
[/list]

Link to comment
Share on other sites

And this is what i get and continue to get

"Command: layerstate-importfromdb

Unknown command "LAYERSTATE-IMPORTFROMDB". Press F1 for help."

 

Its an AutoLISP function, not a command - read the VLIDE Help Documentation.

Link to comment
Share on other sites

I am so lost lol! sorry everyone, i did receive a message what was very interesting. id like to share it and maybe head this direction with it.

 

No need to run this on another machine - ObjectDBX only needs +/-20 seconds to open, change the layer state, and save all 170 drawings. 

THAT is why I suggested it... it's lightning fast!!!

However, there are some restrictions....

For example, you cannot issue normal AutoCAD commands like ._qsave, and ._close. You MUST use Visual LISP syntax functions like vla-open, and vla-close found within the ActiveX COM API.

You can read more about ObjectDBX here, as well as learn some basics for good programming:

Good Habits for Coding in Visual LISP

Here's an excerpt:

                                                        Efficiently Opening Files, or “Warp Speed, Captain!”

ObjectDBX allows you to access drawings without loading them in the  drawing editor. This results in a huge improvement in processing speed  at the expense of not having the user interface. The lack of a user  interface means that you cannot use selection sets. There may also be  issues when modifying objects such as attributes. It is also useful for  decomposing complex objects without the risk of modifying the original  object or its host drawing.

The performance gains make ObjectDBX an excellent tool for querying  multiple drawings. For example, many firms have developed applications  that allow them to create and maintain sheet indexes across hundreds of  drawings in seconds rather than hours.

ObjectDBX cannot directly work on drawings that are read-only or  templates. Therefore, a simple wrapper function that detects those  conditions and provides a temporary drawing file to use in such a case  is useful.

Link to comment
Share on other sites

Yes i understand that, now the question is how can i apply it to a lisp or a objectDBX? what would the code be? Remeber I am trying to restore a layerstate from an imported las file

 

 

I dont get that help screen any longer when you go to autocad 2011 you use online help thats more like online loop without answers.

 

It's a function, not a command.

Call as:

 (layerstate-import <FileNamehere>)

[ATTACH]25755[/ATTACH]

Link to comment
Share on other sites

Say your LAS file is c:\Test.LAS and the state inside it is called StateTest. You import it to the current drawing thus:

(if (layerstate-import "C:\\Test.LAS")
 (princ "Test.LAS has been imported.")
 (princ "There was an error importing Test.LAS")
)

Now to set the StateTest for the model space:

(if (layerstate-restore "StateTest" nil)
 (princ "StateTest has been restored.")
 (princ "There's an error restoring StateTest")
)

If you want to restore the state to a viewport only, you need to first obtain the VP's ename. E.g. if you want to restore the state to all VPs in the current DWG and use VP-overrides instead of setting colours & linetypes for the layers in total:

(setq ss (ssget "_X" '((0 . "VIEWPORT"))) n (sslength ss))
(while (>= (setq n (1- n)) 0)
 (layerstate-restore "StateTest" (ssname ss n) 4)
)

Link to comment
Share on other sites

irneb, I am so very grateful for the help.

 

First off I will be applying these changes to sheet files overall not by viewport so i would assume it be the same approach as if it were model space.

 

Would I need to (command_______) or (defun____) anything? or would the lisp need to look like this?

 


;
(defun c:test)
(if (layerstate-import "I:\DRAWINGS\090-0056 LFMP\Common\ME_Layer_State.las")
 (princ "ME_Layer_State.las has been imported.")
 (princ "There was an error importing ME_Layer_State.las")
)
(if (layerstate-restore "ME_Layer_State" nil)
 (princ "ME_Layer_State has been restored.")
 (princ "There's an error restoring ME_Layer_State")
)

Say your LAS file is c:\Test.LAS and the state inside it is called StateTest. You import it to the current drawing thus:
(if (layerstate-import "C:\\Test.LAS")
 (princ "Test.LAS has been imported.")
 (princ "There was an error importing Test.LAS")
)

Now to set the StateTest for the model space:

(if (layerstate-restore "StateTest" nil)
 (princ "StateTest has been restored.")
 (princ "There's an error restoring StateTest")
)

If you want to restore the state to a viewport only, you need to first obtain the VP's ename. E.g. if you want to restore the state to all VPs in the current DWG and use VP-overrides instead of setting colours & linetypes for the layers in total:

(setq ss (ssget "_X" '((0 . "VIEWPORT"))) n (sslength ss))
(while (>= (setq n (1- n)) 0)
 (layerstate-restore "StateTest" (ssname ss n) 4)
)

Edited by jtk07
Link to comment
Share on other sites

You could generate a command if you like, but the lisp itself don't need to call any command. And the examples I gave just prints to the command line to show if they're successful or not - not really needed. I'd suggest saving this to a SCR file:

(if (layerstate-import "I:\DRAWINGS\090-0056 LFMP\Common\ME_Layer_State.las")
 (layerstate-restore "ME_Layer_State" nil)
)
_QSAVE

Then you use either ScriptPro from AutoDesk or AutoScript from Cadig to run the SCR file on a selection of DWG's.

 

Doing this through ODBX is a lot more difficult, but could possibly go through the DWG's faster. I'm not sure if the layerstate functions work in ODBX, I'm assuming not ... so.

 

To do the same through ODBX you'll need to import the state through ActiveX. Which (in this case) is even more complex than the usual ActiveX, since you need to obtain a LayerStateManager object through:

(vlax-get-or-create-object "AutoCAD.AcadLayerStateManager.VER#")

Where VER# is the major version of the ACad you're using, in your case 18. You can obtain this through:

(itoa (atoi (getvar "acadver")))

Then you need to associate the LS-object with the document object's database. The doc-obj is what you get through ODBX. After that you can finally use the Import and Restore methods of the ls-obj.

Link to comment
Share on other sites

ok so i have created the SCR file and tried to drag and drop and i get this error, any thoughts?

 

Command: (if (layerstate-import "I:\DRAWINGS\090-0056 
LFMP\Common\ME_Layer_State.las")
(_>   (layerstate-restore "ME_Layer_State" nil)
(_> )
nil

Command: _QSAVE
You are trying to save AEC objects to a previous version file format. This is 
not permitted.

These objects can be viewed in a previous version if Proxy Graphics are enabled,
but AEC commands will be disabled.

Users of 2004, 2005 and 2006 versions should install an updated Object Enabler 
(available from [url="http://www.autodesk.com/enablers"]www.autodesk.com/enablers[/url]) before opening these drawings.
Previous versions will display error messages.
Link to comment
Share on other sites

Ohhhh sorry ... :oops: ... I didn't notice. The \ must be doubled in lisp. so you need to have:

(if (layerstate-import "I:\\DRAWINGS\\090-0056 LFMP\\Common\\ME_Layer_State.las")
....

Instead

 

About the AEC warning, that's because your settings are to save to an earlier version DWG file. Check in your Options dialog --> Open and Save tab --> File Save as: ... I think you've got it set to AutoCAD 2004

Link to comment
Share on other sites

i think we are real close now getting this?

 

Command: (if (layerstate-import "I:\\DRAWINGS\\090-0056
(("_> LFMP\\Common\\ME_Layer_State.las")
(_> (layerstate-restore "ME_Layer_State" nil)
(_> )
nil

Command:
SCRIPT
Enter script file name <I:\DRAWINGS\090-0056 LFMP\Sheets\Plumb\PL02-123 
TERMINAL PLUMBING PLAN LEVEL 1 SECTOR M07.scr>:

 

The Save for this project is mandated to 2007 so we auto save down. we can not go earlier than 2007 as it interferes with the AEC objects.

 

Ohhhh sorry ... :oops: ... I didn't notice. The \ must be doubled in lisp. so you need to have:
(if (layerstate-import "I:\\DRAWINGS\\090-0056 LFMP\\Common\\ME_Layer_State.las")
....

Instead

 

About the AEC warning, that's because your settings are to save to an earlier version DWG file. Check in your Options dialog --> Open and Save tab --> File Save as: ... I think you've got it set to AutoCAD 2004

Link to comment
Share on other sites

i think we are real close now getting this?

 

Command: (if (layerstate-import "I:\\DRAWINGS\\090-0056
[b][color=red](("_> [/color][/b]LFMP\\Common\\ME_Layer_State.las")
(_> (layerstate-restore "ME_Layer_State" nil)
(_> )
nil

Command:
SCRIPT
Enter script file name <I:\DRAWINGS\090-0056 LFMP\Sheets\Plumb\PL02-123 
TERMINAL PLUMBING PLAN LEVEL 1 SECTOR M07.scr>:

That seems to be a problem. Is the path split over 2 lines in the SCR file? That shouldn't be. The nil shows that it didn't perform as it should.

 

Could you type / paste the following into your ACad command line?

(findfile "I:\\DRAWINGS\\090-0056 LFMP\\Common\\ME_Layer_State.las")

 

I thought I saw somewhere that ScriptPro is finally upgraded to 64bit. But AutoScript is not needed to be, since it runs inside ACad - it's simply a set of LSP files and DotNet utilities.

Link to comment
Share on other sites

i get "NIL" do you think it could be the 090-0056 LFMP meaning the space?

 

Not the space changed it to 090-0056_LFMP then entered

(findfile "I:\\DRAWINGS\\090-0056_LFMP\\Common\\ME_Layer_State.las")

and get nil still so not the space.

 

I tried to run the command as

Command: (findfile "I:\DRAWINGS\090-0056_LFMP\Common\ME_Layer_State.las") 
"I:\\DRAWINGS"

Link to comment
Share on other sites

No that sounds as if the path is a bit incorrect. Try using this at the command prompt:

(getfiled "" "" "las" 0)

Browse to the file and click Open. It should then show you the "correct" path.

Link to comment
Share on other sites

got the path fixed and created a new Layerstate. Now i am getting this

Command: (if (layerstate-import "I:\\DRAWINGS\\090-0056 
LFMP\\Common\\Layer_States\\MELS.las")
(_> (layerstate-restore "MELS" nil)
(_> )
T

Command:
SCRIPT
Enter script file name <I:\DRAWINGS\090-0056 LFMP\Sheets\Mech\ME02-101 
TICKETING MECHANICAL PLAN LEVEL 1 SECTOR DD22.scr>: 

 

What is T?

 

Why is it restarting another line of scrip?

 

current code

(if (layerstate-import "I:\\DRAWINGS\\090-0056 LFMP\\Common\\Layer_States\\MELS.las")
(layerstate-restore "MELS" nil)
)

Edited by jtk07
Link to comment
Share on other sites

SCR file is working 100% now! Thank you everyone for all the help :)

 

 

got the path fixed and created a new Layerstate. Now i am getting this

Command: (if (layerstate-import "I:\\DRAWINGS\\090-0056 
LFMP\\Common\\Layer_States\\MELS.las")
(_> (layerstate-restore "MELS" nil)
(_> )
T

Command:
SCRIPT
Enter script file name <I:\DRAWINGS\090-0056 LFMP\Sheets\Mech\ME02-101 
TICKETING MECHANICAL PLAN LEVEL 1 SECTOR DD22.scr>: 

What is T?

 

Why is it restarting another line of scrip?

 

current code

(if (layerstate-import "I:\\DRAWINGS\\090-0056 LFMP\\Common\\Layer_States\\MELS.las")
(layerstate-restore "MELS" nil)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...