Lisp to Modify Pipe Label to Add Material Property

Lisp to Modify Pipe Label to Add Material Property

alexka
Advocate Advocate
1,395 Views
3 Replies
Message 1 of 4

Lisp to Modify Pipe Label to Add Material Property

alexka
Advocate
Advocate

I am trying to write a lisp that will allow me to remove and add the pipe material property in a pipe label style. Below is the code that is intended to add the pipe material property to the label style:

 

(defun c:PipeLabelMat  (/)
 (setq style0 (vlax-get (vla-get-activedocument (getpipeapp)) 'pipenetworklabelstyles))
 (setq style1 (vlax-get style0 'PipeLabelStyles))
(setq style2 (vlax-get-property style1 'item "STRM- N"))
(setq style3 (vlax-get-property style2 'textcomponents))
(setq style4 (vlax-get-property style3 'item "Pipe Data"))
(setq style5 (vlax-get-property style4 'Contents))
(vlax-put style5 'value "<[2D Length - Center to Center(Uft|P0|RN|AP|Sn|OF)]>' -  <[Pipe Inner Diameter or Width(Uin|P0|RN|AP|GC|UN|SD|OF)]>\" <[Material(CP)]> @ <[Pipe Slope(FP|P2|RN|AP|Sn|OF)]>\\P ")
(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acAllViewports)
 (princ)
 (princ "\nMaterial Added") 
 (princ))


(defun getpipeapp  (/ c3d verstring prodstring)
 (setq c3d        (strcat "HKEY_LOCAL_MACHINE\\"
                          (if vlax-user-product-key
                           (vlax-user-product-key)
                           (vlax-product-key)))
       c3d        (vl-registry-read c3d "Release")
       verstring  (substr c3d 1 (vl-string-search "." c3d (+ (vl-string-search "." c3d) 1)))
       prodstring (strcat "AeccXUiPipe.AeccPipeApplication." verstring))
 (if (setq c3d (vla-getinterfaceobject (vlax-get-acad-object) prodstring))
  c3d
  nil))

 

When I run the lisp, I get the following:

 

2017-10-01 08_54_26-Autodesk AutoCAD Civil 3D 2018 - [C__Users_alexka_AppData_Local_Microsoft_Window.png

 

but the syntax in the pipe label style looks correct:

 

2017-10-01 09_00_49-Text Component Editor - Contents.png

 

The code seems to work for every property except pipe material. Does anyone know why the pipe material is not recognized or if there is a different way to get the pipe material in the label style.

 

Thank you.

 

0 Likes
1,396 Views
3 Replies
Replies (3)
Message 2 of 4

rapidcad
Collaborator
Collaborator

Hi Alexka, I took a look at it, but without access to C3D, I am left to giving observations. I studied how your calls to styles were coded and structured, as well as the output. I would guess that one of two things might be happening.

1. Material not defined maybe?

2. Your code might be missing a control code to handle the parenthesis or something like that in the material portion. Could the parenthesis throw off the code because they are lisp symbols? I see that everything about the material code including the < > is not evaluating. Does <[Material (CP)]> need a ' or \ before it or some other way to force evaluation or are you just trying to fill in exactly what it says as a string  - that the material is concrete pipe?

 

I'm thinking that you're not evaluating that section or you need a way to trigger evaluation using a certain control code. it might help me suggest something if I knew what you hoped it would spell out exactly. Should it have read "170' - 12" CP @ 0.89% 8" ?

 

BTW, the 8" seems to be odd to me, but I haven't looked at civil piping in decades - can't remember what that might reference.

ADN CAD Developer/Operator
0 Likes
Message 3 of 4

alexka
Advocate
Advocate

@rapidcad,

 

The 8" label is actually labeling an 8" water main crossing (the yellow crossing pipe underneath the storm sewer). The pipe material is RCP and the desired output of the label is 170' - 12" RCP @ 0.89%.

 

Here is the odd thing I've noticed while trying to troubleshoot the lisp; when I first run the lisp, I get the following syntax in the label text component editor and output:

 

2017-10-02 08_11_40-Label Style Composer - STRM- N.png2017-10-02 08_12_03-Autodesk AutoCAD Civil 3D 2018 - [C__Users_alexka_AppData_Local_Microsoft_Window.png

 

However, if I go back into the label text component editor and add the material property to the label from the drop-down on the left, it forces the material property to work in both instances.

 

2017-10-02 08_14_29-Label Style Composer - STRM- N.png

2017-10-02 08_15_14-Autodesk AutoCAD Civil 3D 2018 - [C__Users_alexka_AppData_Local_Microsoft_Window.png

 

It's like the addition of the material property from the drop-down jars C3D into recognizing the syntax for the material property that was added by the lisp. Any thoughts on why this might be happening or how I could simulate this "jarring" in lisp without adding the extra label?

 

Thanks for your help.

 

0 Likes
Message 4 of 4

rapidcad
Collaborator
Collaborator

IDK, but since it works after you dump it in via Autodesk's button in the editor, I think it only needs to evaluate before you try to string it together in your code maybe. Just a guess. You could try setting it to a dummy variable before you try applying the code string, but that's just a guess.

 

One small detail I noticed (I think). No spaces are in the code <[Material(CP)]> when Autodesk generates it, but your string of code seems to include one. I would think it wouldn't matter because you can force yours to work with that trick, but there are many mysteries about code I don't understand.. Try it with no spaces. 

 

OTOH, when I look at the evaluation in the screenshot of the editor, you code seems to have no spaces there. The font in the code is probably fooling me.

ADN CAD Developer/Operator
0 Likes