Set Active Label Style by Picking Existing Label

Set Active Label Style by Picking Existing Label

ROBDOYLE4M9HK
Participant Participant
2,981 Views
11 Replies
Message 1 of 12

Set Active Label Style by Picking Existing Label

ROBDOYLE4M9HK
Participant
Participant

@Jeff_M  provided me a fantastic code snippet in this thread and it has been great for me so far:

https://forums.autodesk.com/t5/civil-3d-forum/direct-command-to-label-pipe-with-specific-style/m-p/1... 

 

I was dreaming and wondering if there is a way to extend it....Ideally it would work like this:

 

  1. You have existing labels already in your drawing (let's just say pipe labels and surface labels as those are what we primarily use)
  2. You type a command (Let's say "CL" for "copy label" routine)
  3. You get a pick box to select an existing label within your drawing
  4. The routine then sets the active label style for that object, just like the code that Jeff_M provided
  5. Possible bonus step - if it was a pipe label selected by the user, the routine will run the 'label pipe' command,. If user selected spot elevation, launch 'spot elevation label' command. Same for a slope label.

Step 5 would really just be a bonus. What I really want is for the active label style to be set to match what the user picked.

 

I just find the "add label' dialog box very cumbersome due to the number of styles we are contending with. I have tried tackling this myself, but I am definitely out of my league here....Thanks in advance to any geniuses out there willing to give me a hand!

0 Likes
Accepted solutions (1)
2,982 Views
11 Replies
Replies (11)
Message 2 of 12

Jeff_M
Consultant
Consultant
Accepted solution

@ROBDOYLE4M9HK attached is a lisp that does the style setting portion for pipe, structure, spot elevation, and slope labels. The command calls could easily be added to the code where shown. I'm just out of time today to do it myself.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 12

ROBDOYLE4M9HK
Participant
Participant

Jeff, this is brilliant!!! Thank you so much!!! I probably will end up adding in code to start the label commands. Thanks for showing where those would go!

 

One other question....is there an online resource or something that lists all of these settings for Civil objects that you are manipulating? For example the things like "slopelabelstyle" , "addsurfacespotelevlabelsettings" , "slopesettings" etc?

 

I see the basic pattern in your code, but don't know the proper names of the settings to enter them into the LISP code. I tried unsuccessfully to use your code from the other thread and modify it to work with spot elevations, but I could never call the settings in the right way.

 

I'm thinking COGO points are the only other thing frequently used, and if I knew how to reference the settings surrounding those, maybe this could work for them too.

 

It would be awesome.....you could "copy" a COGO point by running the routine you provided to set the COGO point style and label style, and then initiate the Add COGO Point command, and you would get a COGO point that looks the exact same, but without the world's most annoying dialog box popping up to ask what to do with your duplicate point numbers. That would be amazing for our workflow!

0 Likes
Message 4 of 12

Jeff_M
Consultant
Consultant

@ROBDOYLE4M9HK wrote:

One other question....is there an online resource or something that lists all of these settings for Civil objects that you are manipulating? For example the things like "slopelabelstyle" , "addsurfacespotelevlabelsettings" , "slopesettings" etc?

 


I basically use 2 things...the COM help file and the Inspect tool in VLIDE. Once you have a variable set rt. click, select Inspect. Then you can double click on any of the properties to Inspect it. Keep doing that to drill down to the property you need to change.

2024-04-18_07-52-56.png

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 12

Jeff_M
Consultant
Consultant

@ROBDOYLE4M9HK wrote:

I'm thinking COGO points are the only other thing frequently used, and if I knew how to reference the settings surrounding those, maybe this could work for them too.

 

It would be awesome.....you could "copy" a COGO point by running the routine you provided to set the COGO point style and label style, and then initiate the Add COGO Point command, and you would get a COGO point that looks the exact same, but without the world's most annoying dialog box popping up to ask what to do with your duplicate point numbers. That would be amazing for our workflow!


Something like this? 😎

(defun c:copycogopoint (/ civdoc landapp newpt pnt points pt ss)
  (setq landapp (getaeccapp "Land")
	civdoc (vlax-get landapp 'activedocument)
	points (vlax-get civdoc 'points)
	)
  (while (setq ss (ssget ":S+." '((0 . "AECC_COGO_POINT"))))
      (setq pnt (vlax-ename->vla-object (ssname ss 0)))
      (setq pt (getpoint (vlax-get pnt 'location) "...new point location: "))
      (setq newpt (vlax-invoke points 'add pt))
      (vlax-put newpt 'rawdescription (vlax-get pnt 'rawdescription))
      (vlax-put newpt 'elevation (vlax-get pnt 'elevation))
      (vlax-put newpt 'style (vlax-get pnt 'style))
      (vlax-put newpt 'labelstyle (vlax-get pnt 'labelstyle))
      (vlax-put newpt 'layer (vlax-get pnt 'layer))
      (vlax-put newpt 'rotation (vlax-get pnt 'rotation))
      (vlax-put newpt 'labelrotation (vlax-get pnt 'labelrotation))
      )
  (vlax-release-object landapp)
  (princ)
  )

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 12

ROBDOYLE4M9HK
Participant
Participant

Again Jeff, this is simply brilliant! I saw it yesterday and struggled through finding a way to blend both of these fantastic routines together. I wasn't very efficient, but I just now got it figured out. You can type "CL" and the respective routine will be run after the code analyzes whether you picked COGO or one of the other entities. I included the final version because I thought it could help others.

 

There's one other question I had about the "Inspect" method you mentioned....when I inspect variables in my code, all I see is "nil" most of the time. I'm assuming I have to start at a higher level and drill down to those properties like you suggested. Can you tell me the path to drill down into the pipe label settings for example? I kept drilling, but never could find my way there.

 

Thanks a million for all your help. The code is awesome! (and I'd like to think I'm a little more educated now too)  😁

 

(defun c:CL (/ ss lbl str)
  (if (setq ss (ssget ":S+."))
    (progn
      (setq lbl (vlax-ename->vla-object (ssname ss 0))
	    str (vla-get-objectname lbl)
	    )
      (cond ((or (wcmatch str "*Pipe*")(wcmatch str "*Structure*"))(setpartstyles lbl))
	    ((or (wcmatch str "*SurfaceElev*")(wcmatch str "*SurfaceSlope*"))(setsurfstyles lbl)))
    
	  (if (eq (cdr (assoc 0 (entget (ssname ss 0)))) "AECC_COGO_POINT")
      (c:copycogopoint ss) 
	  ) 
    )
  )
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
(defun setpartstyles (lbl / cmdsettings doc pipelabelstyle plansettings settings struclabelstyle stylesettings)
  (if (not pipeapp)
    (setq pipeapp (getaeccapp "Pipe"))
    )
  (setq doc (vlax-get pipeapp 'activedocument)
	settings (vlax-get doc 'settings)
	cmdsettings (vlax-get settings 'pipenetworkcommandssettings)
	plansettings (vlax-get cmdsettings 'addnetworkpartplanlabel)
	stylesettings (vlax-get plansettings 'stylesettings)
	pipelabelstyle (vlax-get stylesettings 'pipeplanlabelstyle)
	struclabelstyle (vlax-get stylesettings 'structureplanlabelstyle)
	)
  (if (wcmatch (vla-get-objectname lbl) "*Pipe*")
    (vlax-put pipelabelstyle 'value (vlax-get (vlax-get lbl 'labelstyle) 'name))
    (vlax-put struclabelstyle 'value (vlax-get (vlax-get lbl 'labelstyle) 'name))
  )
  (vl-cmdf "ADDNETWORKPARTPLANLABEL")
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun setsurfstyles (lbl / );;cmdsettings doc settings slopelabelstyle slopesettings spotlabelstyle spotsettings stylesettings)
  (if (not landapp)
    (setq landapp (getaeccapp "Land"))
    )
  (setq doc (vlax-get landapp 'activedocument)
	settings (vlax-get doc 'settings)
	cmdsettings (vlax-get settings 'surfacecommandssettings)
	slopesettings (vlax-get cmdsettings 'addslopelabelsettings)
	slopestylesettings (vlax-get slopesettings 'stylesettings)
	slopelabelstyle (vlax-get slopestylesettings 'slopelabelstyle)
	spotsettings (vlax-get cmdsettings 'addsurfacespotelevlabelsettings)
	spotstylesettings (vlax-get spotsettings 'stylesettings)
	spotlabelstyle (vlax-get spotstylesettings 'spotelevationlabelstyle)
	)
  (if (wcmatch (vla-get-objectname lbl) "*Slope*")
    (progn
      (vlax-put slopelabelstyle 'value (vlax-get (vlax-get lbl 'labelstyle) 'name))
      (vl-cmdf "ADDSURFACESLOPELABEL")
      )
    (progn
      (vlax-put spotlabelstyle 'value (vlax-get (vlax-get lbl 'labelstyle) 'name))
      (vl-cmdf "ADDSURFACESPOTELEVLABEL")
      )
    )
  )
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
 (defun getaeccApp (module / *acad* C3D) ;; module must be "Land", "Pipe", "Roadway", or "Survey"
  (vl-load-com)
  (if (and (setq *acad* (vlax-get-acad-object))
	   (setq C3D (strcat "HKEY_LOCAL_MACHINE\\"
			     (if vlax-user-product-key
			       (vlax-user-product-key)
			       (vlax-product-key)
			     )
		     )
		 C3D (vl-registry-read C3D "Release")
		 C3D (substr
		       C3D
		       1
		       (vl-string-search
			 "."
			 C3D
			 (+ (vl-string-search "." C3D) 1)
		       )
		     )
		 C3D (vla-getinterfaceobject
		       (vlax-get-acad-object)
		       (strcat "AeccXUi" module ".Aecc" (if (= (strcase module) "LAND") "" module) "Application." C3D)
		     )
	   )
      )
    C3D
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun c:copycogopoint (ss / civdoc landapp newpt pnt points pt)
  (setq landapp (getaeccapp "Land")
        civdoc (vlax-get landapp 'activedocument)
        points (vlax-get civdoc 'points))
   
(setq pnt (ssname ss 0)) ; Assign the first entity in ss to pnt
  
  (while
    (progn
      (setq pt (getpoint (vlax-get (vlax-ename->vla-object pnt) 'location) "\nSpecify new point location or press Enter/Escape to exit: "))
      (if pt
        (progn
          ; Create new point at specified location
          (setq newpt (vlax-invoke points 'add pt))
          
          ; Copy properties
          (vlax-put newpt 'rawdescription (vlax-get (vlax-ename->vla-object pnt) 'rawdescription))
          (vlax-put newpt 'elevation (vlax-get (vlax-ename->vla-object pnt) 'elevation))
          (vlax-put newpt 'style (vlax-get (vlax-ename->vla-object pnt) 'style))
          (vlax-put newpt 'labelstyle (vlax-get (vlax-ename->vla-object pnt) 'labelstyle))
          (vlax-put newpt 'layer (vlax-get (vlax-ename->vla-object pnt) 'layer))
          (vlax-put newpt 'rotation (vlax-get (vlax-ename->vla-object pnt) 'rotation))
          (vlax-put newpt 'labelrotation (vlax-get (vlax-ename->vla-object pnt) 'labelrotation))
          
          T ; Continue loop
        )
        ; If pt is nil (user pressed Enter/Escape), exit loop
        nil
      )
    )
  )
  
  (vlax-release-object landapp)
  (princ)
)

 

0 Likes
Message 7 of 12

Jeff_M
Consultant
Consultant

@ROBDOYLE4M9HK wrote:

There's one other question I had about the "Inspect" method you mentioned....when I inspect variables in my code, all I see is "nil" most of the time. I'm assuming I have to start at a higher level and drill down to those properties like you suggested. Can you tell me the path to drill down into the pipe label settings for example? I kept drilling, but never could find my way there.

 

Thanks a million for all your help. The code is awesome! (and I'd like to think I'm a little more educated now too)  😁

 


You're welcome.

Regarding the Inspect...I should've used a different image since that one shows the variable in the middle of a group of setq's. The variable must be set first. In that case I had added a temporary closing paren so I could set the "cmdsettings" variable and inspect that.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 8 of 12

ROBDOYLE4M9HK
Participant
Participant

Jeff,

 

I have been able to extend the LISP for profile labels thanks to your tutelage and your "inspect" trick! But where on earth are the settings for Crossing Pipe Labels???? I have inspected until my eyes hurt, but for some reason I absolutely cannot find them when I perform the drilldown operation.

0 Likes
Message 9 of 12

Jeff_M
Consultant
Consultant

@ROBDOYLE4M9HK wrote:

Jeff,

I have been able to extend the LISP for profile labels thanks to your tutelage and your "inspect" trick! But where on earth are the settings for Crossing Pipe Labels???? I have inspected until my eyes hurt, but for some reason I absolutely cannot find them when I perform the drilldown operation.


You will need to wait for a future release to be able to get those label settings. For whatever reason they have, those have not yet been exposed in the API.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 10 of 12

ROBDOYLE4M9HK
Participant
Participant

Disappointing, but makes me feel a little better that I wasn't missing anything. Seems like an odd exclusion. Oh well, thanks for saving me from continuing down that road

0 Likes
Message 11 of 12

Jeff_M
Consultant
Consultant

@ROBDOYLE4M9HK A slight correction...we may never see the COM API updated with these settings or styles. COM has not been updated much, if at all, since C3D 2012. The Crossing Profile Label Style was not added until fairly recently. It has yet to be added to the .NET API as well.

Jeff_M, also a frequent Swamper
EESignature
Message 12 of 12

saqib_tipa
Advocate
Advocate

 

can you or @Jeff_M please provide code for Profile view labels for structure and pipes.
thank you.

0 Likes