Hello all,
I have been doing some searching and have not yet found anything. I am trying to find or make a way to toggle all of the layers in a drawing that contain cogo points on and off. I calculate points for our survey crews so I'm constantly working with them. Unfortunately, my company does not have a hard and fast layer naming convention for cogo points so they can end up on any number of layers, with any name.
My ultimate goal is to have a single button on my tool bar that when I click it, it turns on and thaws every single layer in the drawing that contains a cogo point. then when I click it again it will freeze every layer that contains a cogo point.
I can see some potential hiccups in that blunt of an operation though. Like if a layer containing a cogo point needs to remain on for line work and other objects, but the cogo point has a style that puts the label and/or marker on a different layer that could be frozen thereby hiding the cogo point label and/or marker.
How would you recommend I create a button like that?
I have a limited knowledge and experience with AutoLISP so hopefully in your reply yo can simplify things so I can learn.
Thanks
Solved! Go to Solution.
Hello all,
I have been doing some searching and have not yet found anything. I am trying to find or make a way to toggle all of the layers in a drawing that contain cogo points on and off. I calculate points for our survey crews so I'm constantly working with them. Unfortunately, my company does not have a hard and fast layer naming convention for cogo points so they can end up on any number of layers, with any name.
My ultimate goal is to have a single button on my tool bar that when I click it, it turns on and thaws every single layer in the drawing that contains a cogo point. then when I click it again it will freeze every layer that contains a cogo point.
I can see some potential hiccups in that blunt of an operation though. Like if a layer containing a cogo point needs to remain on for line work and other objects, but the cogo point has a style that puts the label and/or marker on a different layer that could be frozen thereby hiding the cogo point label and/or marker.
How would you recommend I create a button like that?
I have a limited knowledge and experience with AutoLISP so hopefully in your reply yo can simplify things so I can learn.
Thanks
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@mspeace wrote:
Hello all,
I have been doing some searching and have not yet found anything..... Unfortunately, my company does not have a hard and fast layer naming convention for cogo points so they can end up on any number of layers, with any name. ....
Have you tried...
Layer Filters https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/AutoC...
OR
LAYERSTATE command https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2022/ENU/AutoC...
OR
VIEW command https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/AutoC...
All the above can be "buttons" is that's your usage goal.
@mspeace wrote:
Hello all,
I have been doing some searching and have not yet found anything..... Unfortunately, my company does not have a hard and fast layer naming convention for cogo points so they can end up on any number of layers, with any name. ....
Have you tried...
Layer Filters https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/AutoC...
OR
LAYERSTATE command https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2022/ENU/AutoC...
OR
VIEW command https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/AutoC...
All the above can be "buttons" is that's your usage goal.
Yes and I do have some layer filters set. The issue is, I can not reply on everyone in the company to put cogo points on a layer that contains an identifying string to be filtered. I.E. *-PNTS-* So I need to be able to build a list of all the layers in a drawing that contain a cogo point entity, then use that list to control the state of those layers.
Yes and I do have some layer filters set. The issue is, I can not reply on everyone in the company to put cogo points on a layer that contains an identifying string to be filtered. I.E. *-PNTS-* So I need to be able to build a list of all the layers in a drawing that contain a cogo point entity, then use that list to control the state of those layers.
I don't have anything that uses them, so I can't check this myself, but what is the "entity type" [the DXF-code 0 entry] for a COGO point? If it's distinct from other entity types, it should not be difficult to use an (ssget "_X") function to find all of them, and step through the resulting selection set to put the Layers they're on into a comma-delimited string to use in Layer commands for the toggling.
I don't have anything that uses them, so I can't check this myself, but what is the "entity type" [the DXF-code 0 entry] for a COGO point? If it's distinct from other entity types, it should not be difficult to use an (ssget "_X") function to find all of them, and step through the resulting selection set to put the Layers they're on into a comma-delimited string to use in Layer commands for the toggling.
Here is the result of the DXF
(-1 . <Entity name: 297672b2080>)
(0 . "AECC_COGO_POINT")
(330 . <Entity name: 2976655b9f0>)
(5 . "4A1D0")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "VS-PNTS-1190-220830-VARIOUS GUN JA")
(100 . "AeccDbCogoPoint")
So code 0 is "AECC_COGO_POINT"
Ill have to review the ssget function and how to output the list I need. Its been a long time since I have done anything in AutoLISP (about 10+ years) so I'm extremely rusty.
Here is the result of the DXF
(-1 . <Entity name: 297672b2080>)
(0 . "AECC_COGO_POINT")
(330 . <Entity name: 2976655b9f0>)
(5 . "4A1D0")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "VS-PNTS-1190-220830-VARIOUS GUN JA")
(100 . "AeccDbCogoPoint")
So code 0 is "AECC_COGO_POINT"
Ill have to review the ssget function and how to output the list I need. Its been a long time since I have done anything in AutoLISP (about 10+ years) so I'm extremely rusty.
Here's one way, I think [untested, because I don't...], to give you a string of comma-separated Layer names:
(foreach pt
(mapcar 'cadr (ssnamex (ssget "_X" '((0 . "AECC_COGO_POINT")))))
; find them all, make into list of entity names
(setq lay (cdr (assoc 8 (entget pt)))); Layer name
(if (not (member lay laylist)); not already in the list?
(setq
laylist (cons lay laylist); put in list
laystr (strcat lay "," (cond (laystr) (""))); and build string
)
)
)
Then you can feed laystr into Freeze or Thaw and/or Off or On options in (command "_.layer" ...) functions. After a Thawing one, you may need to REGEN.
Here's one way, I think [untested, because I don't...], to give you a string of comma-separated Layer names:
(foreach pt
(mapcar 'cadr (ssnamex (ssget "_X" '((0 . "AECC_COGO_POINT")))))
; find them all, make into list of entity names
(setq lay (cdr (assoc 8 (entget pt)))); Layer name
(if (not (member lay laylist)); not already in the list?
(setq
laylist (cons lay laylist); put in list
laystr (strcat lay "," (cond (laystr) (""))); and build string
)
)
)
Then you can feed laystr into Freeze or Thaw and/or Off or On options in (command "_.layer" ...) functions. After a Thawing one, you may need to REGEN.
Regards @mspeace
Try this code. Layers report with cogo points
(defun c:lcogo (/ ltl s i ln ltl x ltf)
(setq ltl ())
(setq s (ssget "_a" '((0 . "aecc_cogo_point"))))
(princ "\nLayers report with cogo points...")
(repeat (setq i (sslength s))
(setq sn (entget (ssname s (setq i (1- i))))
ln (cdr (assoc 8 sn))
ltl (cons ln ltl)
)
(setq ltl (vl-sort ltl '<)
ltf (r_doub ltl)
)
)
(foreach x ltf
(print x)
)
(princ)
)
(defun r_doub (lst)
(if lst
(cons (car lst) (r_doub (vl-remove (car lst) lst)))
)
)
Carlos Calderon G
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Regards @mspeace
Try this code. Layers report with cogo points
(defun c:lcogo (/ ltl s i ln ltl x ltf)
(setq ltl ())
(setq s (ssget "_a" '((0 . "aecc_cogo_point"))))
(princ "\nLayers report with cogo points...")
(repeat (setq i (sslength s))
(setq sn (entget (ssname s (setq i (1- i))))
ln (cdr (assoc 8 sn))
ltl (cons ln ltl)
)
(setq ltl (vl-sort ltl '<)
ltf (r_doub ltl)
)
)
(foreach x ltf
(print x)
)
(princ)
)
(defun r_doub (lst)
(if lst
(cons (car lst) (r_doub (vl-remove (car lst) lst)))
)
)
Carlos Calderon G
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
@mspeace wrote:
....
My ultimate goal is to have a single button on my tool bar that when I click it, it turns on and thaws every single layer in the drawing that contains a cogo point. then when I click it again it will freeze every layer that contains a cogo point.
....
And would any COGO point(s) ever be added on some Layer(s) that didn't have any, or all of them on some Layer(s) be deleted, between uses of it? In other words, could the relevant Layer collection be established once, at first use, and the toggling just work with that collection thereafter, or should the relevant Layer collection be re-established with every use, in case the Layer makeup has changed?
@mspeace wrote:
....
My ultimate goal is to have a single button on my tool bar that when I click it, it turns on and thaws every single layer in the drawing that contains a cogo point. then when I click it again it will freeze every layer that contains a cogo point.
....
And would any COGO point(s) ever be added on some Layer(s) that didn't have any, or all of them on some Layer(s) be deleted, between uses of it? In other words, could the relevant Layer collection be established once, at first use, and the toggling just work with that collection thereafter, or should the relevant Layer collection be re-established with every use, in case the Layer makeup has changed?
Most likely yes. I would for sure be creating new layers for points as part of my typical work flow. We download the stored points and put them on their own layer. And Each task we stake, IE curb, storm drain, sewer etc. is separated by layer also.
Most likely yes. I would for sure be creating new layers for points as part of my typical work flow. We download the stored points and put them on their own layer. And Each task we stake, IE curb, storm drain, sewer etc. is separated by layer also.
This only reports a list of the layers that are currently thawed. So almost. I'm sure with a couple minor changes it can get every layer in the drawing regardless of its current state.
This only reports a list of the layers that are currently thawed. So almost. I'm sure with a couple minor changes it can get every layer in the drawing regardless of its current state.
Regards @mspeace
To also include the list of frozen layers with cogo points:
;;;Replace this line...
(setq s (ssget "_a" '((0 . "aecc_cogo_point"))))
;;;For this other...
(setq s (ssget "_X" '((0 . "aecc_cogo_point"))))
Carlos Calderon G
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Regards @mspeace
To also include the list of frozen layers with cogo points:
;;;Replace this line...
(setq s (ssget "_a" '((0 . "aecc_cogo_point"))))
;;;For this other...
(setq s (ssget "_X" '((0 . "aecc_cogo_point"))))
Carlos Calderon G
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Here is what I came up with. It works, I'm pretty sure anyway, still testing.
(defun c:tgpnts ( )
(if (= state nil)
(setq state 1))
(foreach pt
(mapcar 'cadr (ssnamex (ssget "_X" '((0 . "AECC_COGO_POINT")))))
; find them all, make into list of entity names
(setq lay (cdr (assoc 8 (entget pt)))); Layer name
(if (not (member lay laylist)); not already in the list?
(setq
laylist (cons lay laylist); put in list
laystr (strcat lay "," (cond (laystr) (""))); and build string
);end setq
);end if
);end foreach
;;; (print state)
;;; (print laystr)
(if (= state 1)
(command "._layer" "th" laystr "")
nil
); end if
(if (= state -1)
(command "._layer" "fr" laystr "")
nil
); end if
(setq state (* state -1))
(princ);exit quiet
);end tgpnts
Here is what I came up with. It works, I'm pretty sure anyway, still testing.
(defun c:tgpnts ( )
(if (= state nil)
(setq state 1))
(foreach pt
(mapcar 'cadr (ssnamex (ssget "_X" '((0 . "AECC_COGO_POINT")))))
; find them all, make into list of entity names
(setq lay (cdr (assoc 8 (entget pt)))); Layer name
(if (not (member lay laylist)); not already in the list?
(setq
laylist (cons lay laylist); put in list
laystr (strcat lay "," (cond (laystr) (""))); and build string
);end setq
);end if
);end foreach
;;; (print state)
;;; (print laystr)
(if (= state 1)
(command "._layer" "th" laystr "")
nil
); end if
(if (= state -1)
(command "._layer" "fr" laystr "")
nil
); end if
(setq state (* state -1))
(princ);exit quiet
);end tgpnts
@Kent1Cooper I forgot to add credit to your help and your portion of the code in my little tile. So I updated it. Sorry.
; *****************************************************************
; * TOGGLE ALL LAYERS CONTAINING COGO POINTS *
; * BY: Michael Peace With Kent Cooper on the Autodesk Forums *
; * OCTOBER 28, 2022 *
; *****************************************************************
(defun c:tgpnts ( )
(if (= state nil)
(setq state 1))
(foreach pt
(mapcar 'cadr (ssnamex (ssget "_X" '((0 . "AECC_COGO_POINT")))))
; find them all, make into list of entity names
(setq lay (cdr (assoc 8 (entget pt)))); Layer name
(if (not (member lay laylist)); not already in the list?
(setq
laylist (cons lay laylist); put in list
laystr (strcat lay "," (cond (laystr) (""))); and build string
);end setq
);end if
);end foreach
;;; (print state)
;;; (print laystr)
(if (= state 1)
(command "._layer" "th" laystr "")
nil
); end if
(if (= state -1)
(command "._layer" "fr" laystr "")
nil
); end if
(setq state (* state -1))
(princ);exit quiet
);end tgpnts
@Kent1Cooper I forgot to add credit to your help and your portion of the code in my little tile. So I updated it. Sorry.
; *****************************************************************
; * TOGGLE ALL LAYERS CONTAINING COGO POINTS *
; * BY: Michael Peace With Kent Cooper on the Autodesk Forums *
; * OCTOBER 28, 2022 *
; *****************************************************************
(defun c:tgpnts ( )
(if (= state nil)
(setq state 1))
(foreach pt
(mapcar 'cadr (ssnamex (ssget "_X" '((0 . "AECC_COGO_POINT")))))
; find them all, make into list of entity names
(setq lay (cdr (assoc 8 (entget pt)))); Layer name
(if (not (member lay laylist)); not already in the list?
(setq
laylist (cons lay laylist); put in list
laystr (strcat lay "," (cond (laystr) (""))); and build string
);end setq
);end if
);end foreach
;;; (print state)
;;; (print laystr)
(if (= state 1)
(command "._layer" "th" laystr "")
nil
); end if
(if (= state -1)
(command "._layer" "fr" laystr "")
nil
); end if
(setq state (* state -1))
(princ);exit quiet
);end tgpnts
The 1 vs. -1 toggling is interesting, but if I may suggest a simplification:
I would use a variable [with a more routine-specific name, so it's less likely to be overwritten by some other routine] that is either T or nil -- it exists or it doesn't. Then in the Layer command, if it doesn't exist [including at first use], Thaw the Layers, or if it exists, Freeze them. I wouldn't set a default value into it at the top [your first (if) function about the 'state' variable], but would take advantage of the fact that it won't exist until it gets set. You can even incorporate the check for it into one Layer command, instead of spelling that out twice.
Instead of these parts:
(if (= state nil)
(setq state 1))
....
(if (= state 1)
(command "._layer" "th" laystr "")
nil
); end if
(if (= state -1)
(command "._layer" "fr" laystr "")
nil
); end if
(setq state (* state -1))
you could do just this:
(command "_.layer"
(if *COGOshow* "_freeze" "_thaw"); [will Thaw on first use]
laystr ""
)
(setq *COGOshow* (not *COGOshow*)); [reverse state]
The 1 vs. -1 toggling is interesting, but if I may suggest a simplification:
I would use a variable [with a more routine-specific name, so it's less likely to be overwritten by some other routine] that is either T or nil -- it exists or it doesn't. Then in the Layer command, if it doesn't exist [including at first use], Thaw the Layers, or if it exists, Freeze them. I wouldn't set a default value into it at the top [your first (if) function about the 'state' variable], but would take advantage of the fact that it won't exist until it gets set. You can even incorporate the check for it into one Layer command, instead of spelling that out twice.
Instead of these parts:
(if (= state nil)
(setq state 1))
....
(if (= state 1)
(command "._layer" "th" laystr "")
nil
); end if
(if (= state -1)
(command "._layer" "fr" laystr "")
nil
); end if
(setq state (* state -1))
you could do just this:
(command "_.layer"
(if *COGOshow* "_freeze" "_thaw"); [will Thaw on first use]
laystr ""
)
(setq *COGOshow* (not *COGOshow*)); [reverse state]
Thanks Kent. I knew there was a better way, just didn't know how to do it.
Thanks Kent. I knew there was a better way, just didn't know how to do it.
Can't find what you're looking for? Ask the community or share your knowledge.