Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Toggle all layers containing cogo points

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
mspeace
846 Views, 15 Replies

Toggle all layers containing cogo points

mspeace
Contributor
Contributor

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

0 Likes

Toggle all layers containing cogo points

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

Labels (4)
15 REPLIES 15
Message 2 of 16
pendean
in reply to: mspeace

pendean
Community Legend
Community Legend

@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.

0 Likes


@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.

Message 3 of 16
mspeace
in reply to: pendean

mspeace
Contributor
Contributor

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. 

0 Likes

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. 

Tags (1)
Message 4 of 16
Kent1Cooper
in reply to: mspeace

Kent1Cooper
Consultant
Consultant

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.

Kent Cooper, AIA
0 Likes

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.

Kent Cooper, AIA
Message 5 of 16
mspeace
in reply to: Kent1Cooper

mspeace
Contributor
Contributor

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. 

0 Likes

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. 

Message 6 of 16
Kent1Cooper
in reply to: mspeace

Kent1Cooper
Consultant
Consultant

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.

Kent Cooper, AIA
0 Likes

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.

Kent Cooper, AIA
Message 7 of 16
calderg1000
in reply to: mspeace

calderg1000
Mentor
Mentor

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
EESignature
>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.

0 Likes

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
EESignature
>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.

Message 8 of 16
Kent1Cooper
in reply to: mspeace

Kent1Cooper
Consultant
Consultant

@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?

Kent Cooper, AIA
0 Likes


@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?

Kent Cooper, AIA
Message 9 of 16
hosneyalaa
in reply to: mspeace

hosneyalaa
Advisor
Advisor

Hi @mspeace 

This is helpful for you 

 

(setq layer (vlax-get-property cogo 'Layer))
 

 

https://forums.autodesk.com/t5/civil-3d-customization/exporting-cogo-points-with-layer-information-a...

0 Likes

Hi @mspeace 

This is helpful for you 

 

(setq layer (vlax-get-property cogo 'Layer))
 

 

https://forums.autodesk.com/t5/civil-3d-customization/exporting-cogo-points-with-layer-information-a...

Message 10 of 16
mspeace
in reply to: Kent1Cooper

mspeace
Contributor
Contributor

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. 

0 Likes

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. 

Message 11 of 16
mspeace
in reply to: calderg1000

mspeace
Contributor
Contributor

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.

0 Likes

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.

Message 12 of 16
calderg1000
in reply to: mspeace

calderg1000
Mentor
Mentor

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
EESignature
>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.

0 Likes

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
EESignature
>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.

Message 13 of 16
mspeace
in reply to: Kent1Cooper

mspeace
Contributor
Contributor

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
0 Likes

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
Message 14 of 16
mspeace
in reply to: mspeace

mspeace
Contributor
Contributor

@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
0 Likes

@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
Message 15 of 16
Kent1Cooper
in reply to: mspeace

Kent1Cooper
Consultant
Consultant
Accepted solution

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]
Kent Cooper, AIA
0 Likes

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]
Kent Cooper, AIA
Message 16 of 16
mspeace
in reply to: Kent1Cooper

mspeace
Contributor
Contributor

Thanks Kent. I knew there was a better way, just didn't know how to do it.

0 Likes

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.

Post to forums  

Rail Community


Autodesk Design & Make Report