Lisp to set waterdrop width

Lisp to set waterdrop width

M_c3d
Advisor Advisor
1,340 Views
11 Replies
Message 1 of 12

Lisp to set waterdrop width

M_c3d
Advisor
Advisor

Hi All,

 

I'm trying to amend the waterdrop command to set the layer and width of the 2d polyline it creates.

 

The layer changes ok, but the plinewid variabe doesnt apply to the polyline created.


Any ideas? 

 

Thanks in advance!

 

(command "_.undefine" "AeccCreateSurfaceWaterDrop")
(defun C:AeccCreateSurfaceWaterDrop () (setvar 'clayer "Surface Water Flow Path") (setvar 'plinewid 0.1) (command "_.AeccCreateSurfaceWaterDrop"))

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

Jeff_M
Consultant
Consultant

This should do it.

 

(defun C:AeccCreateSurfaceWaterDrop (/ PLINE plines lastent)
  (setq lastent (entlast))
  (command "_.AeccCreateSurfaceWaterDrop")
  (while (= 1 (getvar 'cmdactive))
    (command PAUSE)
    (if (/= (entlast) lastent)
      (setq plines (cons (entlast) plines))
      )
    )
  (foreach ent plines
    (setq pline (vlax-ename->vla-object ent))
    (vla-put-constantwidth pline 0.1)
    (vla-put-layer pline "Surface Water Flow Path")
    )
  (princ)
  )

 

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

M_c3d
Advisor
Advisor

Hi @Jeff_M 

 

Thanks for your help, it comes up with the error noted below.  The layer for the polyline created hasn't changed.

 

Thanks,

 

Command: AECCCREATESURFACEWATERDROP
_.AeccCreateSurfaceWaterDrop
Surface: Surface1 (1)

Select point:
Select point:

Command: ; error: ActiveX Server returned the error: unknown name: ConstantWidth

0 Likes
Message 4 of 12

Jeff_M
Consultant
Consultant
What C3D version are you using? I tested this in C3D 2018 and it worked well.
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 5 of 12

M_c3d
Advisor
Advisor

r2021

0 Likes
Message 6 of 12

Jeff_M
Consultant
Consultant
Add the line (vl-load-com) to the start of the lisp. Also, I changed the code I posted above to add the plines and lastent variables to the locals list.
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 7 of 12

M_c3d
Advisor
Advisor

It still comes up with the error;

 

Command: ; error: ActiveX Server returned the error: unknown name: ConstantWidth

 

Just to check, current lisp below;

 

(vl-load-com)
(defun C:AeccCreateSurfaceWaterDrop (/ PLINE)
(setq lastent (entlast))
(command "_.AeccCreateSurfaceWaterDrop")
(while (= 1 (getvar 'cmdactive))
(command PAUSE)
(if (/= (entlast) lastent)
(setq plines (cons (entlast) plines))
)
)
(foreach ent plines
(setq pline (vlax-ename->vla-object ent))
(vla-put-constantwidth pline 0.1)
(vla-put-layer pline "Surface Water Flow Path")
)
(princ)
)

0 Likes
Message 8 of 12

Jeff_M
Consultant
Consultant
Accepted solution

Strange. I just tested it in C3D 2021 and it works fine. Wait, looks like you have the Waterdrop tool creating 3d polylines. The default is 2d. 3dPolys do not have a width property. This accounts for either a 2d or 3d poly.

 

(command "_.undefine" "AeccCreateSurfaceWaterDrop")
(defun C:AeccCreateSurfaceWaterDrop (/ PLINE LASTENT PLINES)
  (setq lastent (entlast))
  (command "_.AeccCreateSurfaceWaterDrop")
  (while (= 1 (getvar 'cmdactive))
    (command PAUSE)
    (if (/= (entlast) lastent)
      (setq plines (cons (entlast) plines))
      )
    )
  (foreach ent plines
    (setq pline (vlax-ename->vla-object ent))
    (if (/= "AcDb3dPolyline" (vla-get-objectname pline))
      (vla-put-constantwidth pline 0.1)
      )
    (vla-put-layer pline "Surface Water Flow Path")
    )
  (princ)
  )

 

 

Jeff_M, also a frequent Swamper
EESignature
Message 9 of 12

M_c3d
Advisor
Advisor

Hi @Jeff_M I still couldn't get it to work.

 

I did a reset of civil 3d and then added the lisp to the acaddoc.lsp file and suddenly it now works brilliantly! Not sure why it needed a reset.

 

Thanks, appreciate your help

0 Likes
Message 10 of 12

M_c3d
Advisor
Advisor

Hi @Jeff_M 

 

I've noticed that it sometimes leaves some of the flow paths as they were rather than changing the layer and width.  Any ideas?  I've attached a gif of it.

 

Thanks,Flow path.gif

0 Likes
Message 11 of 12

Jeff_M
Consultant
Consultant
Yes, I noticed that as well. I'm looking into it now.
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 12 of 12

Jeff_M
Consultant
Consultant

@M_c3d here is a version that checks for the existence of the desired layer, creates it if needed, sets the C3D command setting for the waterdrop layer, creates the plines, then correctly changes the width of the plines.

 

(command "_.undefine" "AeccCreateSurfaceWaterDrop")
(vl-load-com)
(defun C:AeccCreateSurfaceWaterDrop (/ PLINE LASTENT c3d c3ddoc surfsetting dwg layer layername)
  (setq layername "Surface Water Flow Path")
  (if (not (tblsearch "Layer" layername))
    (progn
      (setq dwg (vla-get-activedocument (vlax-get-acad-object)))
      (setq layer (vla-add (vla-get-layers dwg) layername))
      (vla-put-color layer 4)
      ;;here you can set the layer color and linetype
      )
    )
  
  (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 "AeccXUiLand.AeccApplication." C3D)
		     )
	   )
  (setq C3Ddoc (vla-get-activedocument C3D))
  (setq surfsetting (vlax-get (vlax-get (vlax-get c3ddoc 'settings) 'surfacecommandssettings) 'createsurfacewaterdropsettings))
  (vlax-put (vlax-get surfsetting 'pathlayer) 'value layername)
  (setq lastent (entlast))
  (command "_.AeccCreateSurfaceWaterDrop")
  (while (= 1 (getvar 'cmdactive))
    (command PAUSE)
    )
  (while (setq lastent (entnext lastent))
    (setq pline (vlax-ename->vla-object lastent))
    (if (/= "AcDb3dPolyline" (vla-get-objectname pline))
      (vla-put-constantwidth pline 0.1)
      )
    )
  (princ)
  )

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes