LISP Routine to Edit Common Field of Multiple Civil 3D Styles

LISP Routine to Edit Common Field of Multiple Civil 3D Styles

CogoCody
Enthusiast Enthusiast
1,013 Views
5 Replies
Message 1 of 6

LISP Routine to Edit Common Field of Multiple Civil 3D Styles

CogoCody
Enthusiast
Enthusiast

I'm looking to make better use of these label styles and use Civil 3D object labels more frequently. One thing I run into though is I often need to alter the text content of label styles to enter information (e.g., from survey notes).  As this happens, I might need to adjust the height of the text to fit different deliverables that go out the door. 

 

My issue here being if I create multiple styles for these notes to have different heights, the change from one style to another erases the modified text content. If I want to edit the heights of the existing styles, I have to go style by style. 

 

It would be nice to write a lisp routine that either bulk edit a common field across multiple styles based on a set of selected objects (e.g. Text Hight), or allows me to change object styles of an object (e.g. Note Label) while retaining the original text content. 

 

I'm not familiar with LISP syntax (though I do have programming experience) and am curious how I retrieve the object properties of a civil 3d object, its style, then make edits to the field(s) of said style to achieve this outcome. Any help with the relevant methods for extracting this data would be much appreciated. My key assumptions here are that all the styles I select would have a common component (e.g., Text) and a common field to edit. These would be hardcoded into the routine and checked for errors.

 

I tried the 'dumpallproperties' command, but it seemed to only grab the AutoCAD properties, nothing associated with the Civil 3D styles under the settings tab.

 

Or help with a different workflow to better use the Note Label styles would also be good!

 

Thanks in advance! 

 

codyD45HY_0-1697647248473.png

 

codyD45HY_1-1697647316441.png

 

0 Likes
Accepted solutions (2)
1,014 Views
5 Replies
Replies (5)
Message 2 of 6

Jeff_M
Consultant
Consultant
Accepted solution

Here is a quick example to select a Note label, get the style used for that label, then update the text height for all text components used in that style to be 0.08" plotted height.

(defun c:notetextheight80 (/ ss lbl style txtcomponents)
  (if (setq ss (ssget "_:S+." '((0 . "AECC_GENERAL_NOTE_LABEL"))))
    (progn
      (setq lbl (vlax-ename->vla-object (ssname ss 0)))
      (setq style (vlax-get lbl 'labelstyle)
	    txtcomponents (vlax-get style 'textcomponents)
	    )
      (vlax-for comp txtcomponents
	(vlax-put comp 'height (/ 0.08 12));;0.08" plotted height
	)
      )
    )
  (princ)
  )
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 6

CogoCody
Enthusiast
Enthusiast

I appreciate the response! That definitely gives me a path for making a function and simple solution for the time being. For my own edification, properties like the AECC_GENERAL_NOTE_LABEL and 'height' field that was modified in textcomponents, how would I inspect those objects to see the names of the field?. 

 

For example, I might have guessed the field name for height was 'Text Height' based on the gui for the style editor. Where would be a good resource/method to see the name of the variable controlling the value of the Text Height field so I know where to 'put' the new values?

 

codyD45HY_0-1697652831407.png

 

0 Likes
Message 4 of 6

Jeff_M
Consultant
Consultant
Accepted solution

The DXF Name of the object can be easily found by using the LIST command in C3D and selecting the object:

Command: li LIST
Select objects: 1 found

Select objects:
AECC_GENERAL_NOTE_LABEL Layer: "C-ANNO"
Space: Model space
Handle = 93be

 

The Civil 3D COM API reference has the properties and methods for the C3D objects. HERE is the link to the TextComponent object

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 6

CogoCody
Enthusiast
Enthusiast

You're a life saver, that API reference is precisely what I've been after. Thank you kindly for all your help!

0 Likes
Message 6 of 6

BlackBox_
Advisor
Advisor

Thanks, @Jeff_M !

 

I've wanted something like this for a long time.

 

Slight mod to also adjust dragged state w/stacked text: 

 

(defun c:SetLabelStyleTextHeight (/ *error* textHeight acDoc ss oStyle styleName styleNames oStyles oStyleDragged)

  (defun *error* (msg)
    (if	ss
      (vla-delete ss)
    )
    (if	acDoc
      (vla-endundomark acDoc)
    )
    (cond ((not msg))							 ; Normal exit
	  ((member msg '("Function cancelled" "quit / exit abort")))	 ; <esc> or (quit)
	  ((princ (strcat "\n** Error: " msg " ** ")))			 ; Fatal error, display it
    )
    (princ)
  )

  (if
    (and
      (ssget "_:L" '((0 . "AECC_*_LABEL")))
      (or *LabelStyleTextHeight*
	  (setq *LabelStyleTextHeight* 0.08)
      )
      (or
	(setq textHeight
	       (getreal
		 (strcat "\nSpecify label style text height (in INCHES) <"
			 (rtos *LabelStyleTextHeight* 2 3)
			 ">: "
		 )
	       )
	)
	(setq textHeight *LabelStyleTextHeight*)
      )
      (< 0.0 textHeight)
      (setq *LabelStyleTextHeight* textHeight)
      (princ)
    )
     (progn
       (setq textHeight (/ textHeight 12))
       (vla-startundomark
	 (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
       )
       (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
	 (setq oStyle (vlax-get x 'labelstyle))
	 (if
	   (not
	     (vl-position
	       (setq styleName (vla-get-name oStyle))
	       styleNames
	     )
	   )
	    (progn
	      (setq styleNames (cons styleName styleNames))
	      (setq oStyles (cons oStyle oStyles))
	    )
	 )
       )
       (foreach	oStyle oStyles
	 (vlax-for comp	(vlax-get oStyle 'textcomponents)
	   (vlax-put comp 'height textHeight)
	 )
	 (if
	   (= -1
	      (vlax-get
		(vlax-get
		  (setq	oStyleDragged
			 (vlax-get oStyle
				   'draggedcomponentstyle
			 )
		  )
		  'stacktext
		)
		'value
	      )
	   )
	    (vlax-put (vlax-get oStyleDragged 'textheight)
		      'value
		      textHeight
	    )
	 )
	 (prompt (strcat "\n >> Style: \""
			 (vla-get-name oStyle)
			 "\" modified. "
		 )
	 )
       )
     )
     (if (= 0.0 textHeight)
       (prompt "\nValue must greater than zero. ")
     )
  )
  (*error* nil)
)

 


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps