View Full Version : Automation of layer state Saving/Restoring
jrd.chapman
2005-01-03, 05:44 PM
When saving a layer state from the command line, the Current VP Freeze status is not included. NewVPFreeze status get included, but not the current viewport status.
When saving through the later states dialog in 2005, you can check a box to include the Current VP Freeze status. If you use the MSPACE command to enter a viewport, then enter the layer dialog, you can successfully save the layer state, including all layers frozen in the current viewport.
Once successfully saved, you can now only successfully restore it through the dialog as well. Trying to restore from the command line while inside your viewport does not work.
Does anyone know why the command line does not offer the same functionality as the dialog?
I am writing a routine that iterates though each layout in a drawing, uses the MSPACE command to enter each viewport, and save the layer state. It works just fine, except for the inability to successfully save the CURRENT viewport freeze status. I have tried all the suggestions I could find here and elsewhere, but I can get nothing to REALLY do what I need.
I have some suspicion that the reason none of the suggestions I've read here have worked may be due to a combination of: layer naming, and the number of layers frozen in the current viewport. Layer names contain spaces, and there are 65-75 layers frozen in any given viewport. Could these factors cause difficulty for any kind of programming to successfully extract ALL the data from the viewport? It seems to me from some minimal investigation that the data may become truncated or cut off, and therefore not ALL of the viewport layer info gets extracted when trying to save the state of layers within it.
Sorry for the long-winded post. Hopefully you can read through it thoroughly enough to decipher what I am trying to accomplish. If anyone has any suggestions or advice, I would greatly appreciate it.
Thanking you in advance!
RobertB
2005-01-03, 07:39 PM
Layer visibility settings for viewports are stored as XData attached to each viewport.
jrd.chapman
2005-01-03, 08:09 PM
Hi Robert,
Layer visibility settings for viewports are stored as XData attached to each viewport.Yes,
I've been trying to extract that data, however, when I list the Xdata of one of the viewports in question, the DXF code 1003 entries only list 5 of the 66 layers actually frozen in that viewport.
Listing the Xdata seems to get "cut-off" before encountering the closing brace (DXF code 1002) for the layer data......not sure why.
Here is an example of what gets listed by a simple (entsel)
Command: (ENTGET (CAR (ENTSEL)) '("*"))
name: 7edabdc8>) (331 . <Entity name: 7edabe00>) (331 . <Entity name:
7edabe40>) (331 . <Entity name: 7ede3c90>) (331 . <Entity name: 7ede3ca0>) (331
. <Entity name: 7efa4c30>) (331 . <Entity name: 7efa4c38>) (90 . 49152) (281 .
0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79
. 0) (146 . 0.0) (170 . 0) (-3 ("ACAD" (1000 . "MVIEW") (1002 . "{") (1070 .
16) (1010 4047.23 4502.75 2712.83) (1010 0.0 0.0 376.462) (1040 . 0.0) (1040 .
100.0) (1040 . 0.0) (1040 . 0.0) (1040 . 50.0) (1040 . 0.0) (1040 . 0.0) (1070
. 0) (1070 . 2000) (1070 . 1) (1070 . 0) (1070 . 0) (1070 . 0) (1070 . 0) (1070
. 0) (1040 . 0.0) (1040 . 0.0) (1040 . 0.0) (1040 . 1.0) (1040 . 1.0) (1040 .
0.0) (1040 . 0.0) (1070 . 0) (1002 . "{") (1003 . "P-GRADE-BORROW") (1003 .
"HIGH-WATER") (1003 . "ELEV-CO") (1003 . "ELEV-BH") (1003 . "P-GRADE"))))31 .
<Entity name: 7ed199b0>) (331 . <Entity name: 7ed199b8>) (331 . <Entity name:
7ed199d0>) (331 . <Entity name: 7ed199f0>) (331 . <Entity name: 7ed199f8>) (331
. <Entity name: 7ed19a18>) (331 . <Entity name: 7ed19a48>) (331 . <Entity name:
7ed19a78>) (331 . <Entity name: 7ed19a90>) (331 . <Entity name: 7ed19ac0>) (331
. <Entity name: 7ed19ac8>) (331 . <Entity name: 7ed19ad0>) (331 . <Entity name:
7ed19ae0>) (331 . <Entity name: 7ed19b50>) (331 . <Entity name: 7ed19b80>) (331
. <Entity name: 7ed19b88>) (331 . <Entity name: 7ed19b90>) (331 . <Entity name:
7ed19b98>) (331 . <Entity name: 7ed19c48>) (331 . <Entity name: 7ed19c58>) (331
. <Entity name: 7ed19c68>) (331 . <Entity name: 7ed19c78>) (331 . <Entity name:
7ed19c88>) (331 . <Entity name: 7ed19cc0>) (331 . <Entity name: 7ed19cc8>) (331
. <Entity name: 7ed19cd0>) (331 . <Entity name: 7ed19cd8>) (331 . <Entity name:
7ed19ce0>) (331 . <Entity name: 7ed19ce8>) (331 . <Entity name: 7ed19cf0>) (331
. <Entity name: 7ed19cf8>) (331 . <Entity name: 7ed19d00>) (331 . <Entity name:
7ed19d40>) (331 . <Entity name: 7ed19d48>) (331 . <Entity name: 7ed19d50>) (331
. <Entity name: 7ed19d80>) (331 . <Entity name: 7ed19d88>) (331 . <Entity name:
7ed19d90>) (331 . <Entity name: 7ed19da0>) (331 . <Entity name: 7ed19da8>) (331
. <Entity name: 7ed19db0>) (331 . <Entity name: 7ed19dc0>) (331 . <Entity name:
7ed19eb0>) (331 . <Entity name: 7ed19ec8>) (331 . <Entity name: 7ed19ed8>) (331
. <Entity name: 7ed19ee8>) (331 . <Entity name: 7ed19f08>) (331 . <Entity name:
7ed19f10>) (331 . <Entity name: 7ed20cc8>) (331 . <Entity name: 7ed20d70>) (331
. <Entity name: 7ed20d78>) (331 . <Entity name: 7ed24808>) (331 . <Entity name:
7ed509e8>) (331 . <Entity name: 7ed524f0>) (331 . <Entity name: 7ed56e90>) (331
. <Entity name: 7ed5c700>) (331 . <Entity name: 7ed5e230>) (331 . <Entity name:
7ed5e4e8>) (331 . <Entity name: 7ed5e600>) (331 . <Entity name: 7ed73638>) (331
. <Entity name: 7ed7e860>) (331 . <Entity name: 7ed8c320>) (331 . <Entity name:
7ed8c378>) (331 . <Entity name: 7ed8c380>) (331 . <Entity name: 7ed8c390>) (331
. <Entity name: 7ed8f2a0>) (331 . <Entity name: 7ed8f328>) (331 . <Entity name:
7ed8f378>) (331 . <Entity name: 7ed8f608>) (331 . <Entity name: 7ed8f6b8>) (331
. <Entity name: 7ed8f730>) (331 . <Entity name: 7ed93048>) (331 . <Entity name:
7ed930f0>) (331 . <Entity name: 7ed931f0>) (331 . <Entity name: 7ed93290>) (331
. <Entity name: 7ed93438>) (331 . <Entity name: 7ed96838>) (331 . <Entity name:
7ed98ae8>) (331 . <Entity name: 7ed98c40>) (331 . <Entity name: 7ed98f58>) (331
. <Entity name: 7ed99030>) (331 . <Entity name: 7eda15f8>) (331 . <Entity name:
7eda1610>) (331 . <Entity name: 7eda5248>) (331 . <Entity name: 7eda5250>) (331
. <Entity name: 7eda5258>) (331 . <Entity name: 7eda5260>) (331 . <Entity name:
7eda5268>) (331 . <Entity name: 7eda5270>) (331 . <Entity name: 7eda5288>) (331
. <Entity name: 7eda5298>) (331 . <Entity name: 7eda52a0>) (331 . <Entity name:
7eda52a8>) (331 . <Entity name: 7eda52b0>) (331 . <Entity name: 7eda52b8>) (331
. <Entity name: 7eda52d8>) (331 . <Entity name: 7eda52e8>) (331 . <Entity name:
7eda52f0>) (331 . <Entity name: 7eda5300>) (331 . <Entity name: 7edabd90>) (331
. <Entity name: 7edabdb0>) (331 . <Entity
....you can see above that a DXF code 1002 closing brace is not encountered....it just seems to "cut-off" or "cop-out" without successfully listing ALL of the viewports data. The same occurs when using the Express Tools XDLIST command:
Command:
XDLIST
Select object:
Enter application name <*>: ACAD
* Registered Application Name: ACAD
* Code 1000, ASCII string: MVIEW
* Code 1002, Starting or ending brace: {
* Code 1070, 16-bit integer: 16
* Code 1010, 3 real numbers: (4047.23 4502.75 2712.83)
* Code 1010, 3 real numbers: (0.00 0.00 376.46)
* Code 1040, Real number: 0.00
* Code 1040, Real number: 100.00
* Code 1040, Real number: 0.00
* Code 1040, Real number: 0.00
* Code 1040, Real number: 50.00
* Code 1040, Real number: 0.00
* Code 1040, Real number: 0.00
* Code 1070, 16-bit integer: 0
* Code 1070, 16-bit integer: 2000
* Code 1070, 16-bit integer: 1
* Code 1070, 16-bit integer: 0
* Code 1070, 16-bit integer: 0
* Code 1070, 16-bit integer: 0
* Code 1070, 16-bit integer: 0
* Code 1070, 16-bit integer: 0
-More-
* Code 1040, Real number: 0.00
* Code 1040, Real number: 0.00
* Code 1040, Real number: 0.00
* Code 1040, Real number: 1.00
* Code 1040, Real number: 1.00
* Code 1040, Real number: 0.00
* Code 1040, Real number: 0.00
* Code 1070, 16-bit integer: 0
* Code 1002, Starting or ending brace: {
* Code 1003, Layer name: P-GRADE-BORROW
* Code 1003, Layer name: HIGH-WATER
* Code 1003, Layer name: ELEV-CO
* Code 1003, Layer name: ELEV-BH
* Code 1003, Layer name: P-GRADE
Object has 16383 bytes of Xdata space available.
Any routine I've tried that will try and create a list of the layers frozen in the viewport will extract this information, which, as seen above, seems incomplete. Therefore, if, for some reason I lose the state of my layers within the viewport (i.e. if I copy the viewport) and try to restore from a text file created from the viewports seemingly incomplete Xdata, only those 5 layers extracted from the Xdata will be Re-Frozen.
Am I doing something wrong in trying to extract ALL 66 frozen layers from the viewport I'm using as an example?
Any suggestions?
RobertB
2005-01-03, 08:32 PM
Use the VLIDE object browser to view the XData. The command prompt is limited in how much data it can show. All your data is there.
(defun GetVPFrozen (vportEName / eData xData resList)
(setq eData (entget vportEName (list "ACAD")))
(setq xData (cdadr (assoc -3 eData)))
(foreach datum xData
(cond ((= (car datum) 1003) (setq resList (cons (cdr datum) resList)))))
(reverse resList))
jrd.chapman
2005-01-03, 09:51 PM
Use the VLIDE object browser to view the XDataI don't really understand what you mean? How do I do this? I've never used this to view data.
Also, why does the following Express Tools command still only return a neat and tidy list of only 5 layers? Is there something functionally wrong with the way Express Tools extracts the information?
Command: (ACET-VIEWPORT-FROZEN-LAYER-LIST (ACET-CURRENTVIEWPORT-ENAME))
("P-GRADE-BORROW" "HIGH-WATER" "ELEV-CO" "ELEV-BH")]
RobertB
2005-01-03, 11:06 PM
I don't know why the Express Tools function returns what is does. Guess that's just one more reason to use my own code.
See the attached image for the VLIDE browsing that I mentioned.
kennet.sjoberg
2005-01-04, 09:48 AM
Hi chippychaps, if the program use list there is a limitation in showing the items
(setq MyList (list
or
(setq MyList (vl-list*
if You have a lot of items in a list it will be truncated like
(aa bb cc) (dd ee ff) (xx xx xx) (yy yy yy)
---- skipped ----|<-------- shown -------->|
I can not figure out the limit, because it seems to be random in size
but list can keep many more items than vl-list* which give You an error
You can check the first and last items in the list with (nth 0 MyList) and (last MyList)
: ) Happy Computing !
kennet
thomas.stright
2005-01-04, 12:05 PM
I can not figure out the limit, because it seems to be random in size
Is'nt the limit bound by availible memory?
kennet.sjoberg
2005-01-04, 12:57 PM
Is'nt the limit bound by availible memory?
. . . figure out
Happy Computing !
: ) kennet
jrd.chapman
2005-01-05, 04:10 PM
Thanks all for responding. I think I'm on the path I want to be on. With Roberts code to help jumpstart me, I can finally get this code to return an accurate number of layers frozen in the selected viewport.
(defun GetVPFrozen (/ vportEName ent etyp vportEName CNT eData xData resList)
(if (not (dictsearch (namedobjdict) "Ainley"))
(vpdict)
)
(setq etyp nil)
(while (/= etyp "VIEWPORT")
(setq vportEName (ssget '((0 . "VIEWPORT"))))
(while (not vportEName)
(setq vportEName (ssget '((0 . "VIEWPORT"))))
)
(setq CNT 0)
(repeat (sslength vportEName)
(setq ent (entget (ssname vportEName CNT))
etyp (cdr (assoc 0 ent))
)
(setq CNT (1+ CNT))
)
)
(setq CNT 0)
(repeat (sslength vportEName)
(setq eData (entget (ssname vportEName CNT) (list "ACAD")))
(setq xData (cdadr (assoc -3 eData)))
(foreach datum xData
(cond ((= (car datum) 1003)
(setq resList (cons (cdr datum) resList))
)
)
)
(setq resList (acad_strlsort (reverse resList)))
(alert (strcat "\nThere are " (itoa (length resList)) " layers frozen in this viewport."))
(vlax-ldata-put "Ainley" (getvar "ctab") resList)
(setq CNT (1+ CNT))
)
(princ)
)
Now I'm on my way to writing the function to restore these layer states in my viewports. I may be back with more questions as I go, but for now I think I'm on my way. Thanks again so much to everyone responding, especially to Robert, a.k.a. "guru of gurus" for the jumpstart.
Take care!
RobertB
2005-01-05, 04:36 PM
Thanks all for responding. I think I'm on the path I want to be on. With Roberts code to help jumpstart me, I can finally get this code to return an accurate number of layers frozen in the selected viewport.
...
Now I'm on my way to writing the function to restore these layer states in my viewports. I may be back with more questions as I go, but for now I think I'm on my way. Thanks again so much to everyone responding, especially to Robert, a.k.a. "guru of gurus" for the jumpstart.
Glad I could help.
BTW, I noticed that you are using LData. I would strongly recommend not using LData, but rather use straight Dictionary/XRecord functions. LData cannot be read by VBA, and might not be available via .NET either. Very bad for long-term data storage.
jrd.chapman
2005-01-06, 07:53 PM
Thanks for the advice Robert. Right now, I'm really just doing that (saving Ldata) due to it's ease (ease for me, as I have not explored Dictionary/XRecord functions yet). Just a quick way for me to save and restore the list of layers until I know I have the application running the way I like.
Regarding the original topic, I am still perplexed by some behaviour I'm seeing: I still have some viewports that just WILL NOT add some layers that are frozen within it to it's Xdata....really....I'm not kidding here (even in VLIDE, the list is incomplete). I have a few layouts on one particular drawing that act very strange. Neither Robert's code, or Express Tools code will save an accurate list (e.g. both Robert's code and Express Tools will save 47 of 64 layers frozen in the viewport). Some viewports in this drawing, however, will save an accurate list. One accurately saves a list of 195 layers frozen, and ALL 195 of them show up on the command line without being truncated. So, this isn't an issue with limitations in how much of the list will be shown to me.
Maybe there is just some sort of corruption in the drawing I'm having trouble with, I don't know.
This all started out because I wondered why the built in AutoCAD layer states command does not allow you to save the "Current Viewport Freeze" status from the command line. This would be nice because it is the only thing that works accurately in this one drawing. But, It only allows you to do this from the dialog. It would be nice from the command line because then I could use it in my automation.
Does anyone know of a way from the command line to include the "Current Viewport Freeze" status when saving a layer state with the built-in AutoCAD command?
Thanks again!
peter
2006-10-26, 11:28 PM
Layer visibility settings for viewports are stored as XData attached to each viewport.
Hey Bob,
Have you been able to read the xdata from a viewport and modify it and replace the xdata on a viewport, and change the layer settings of the viewport?
I have tried several times and have not been successful. I have only found the vplayer to be the only way to do it. If you have a solution I would like to see it.
Peter
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.