Jump to content

Could someone please have a look at this short Cogo point creation script?


Recommended Posts

Hi everyone, I hope y'all are doing well.

 

Could someone please have a look at this Cogo point creation script that I got for Civil 3D?  It's a lisp script that allows the user to create a Cogo point by snapping to an object and the Cogo point will inherits the X,Y,Z position. I have been using this script to snap to point cloud data to get the X,Y,Z position of the center of sewer lids and then giving it a point description.

 

Basically, the script works like this. I activate the script and it will ask me to select a point. I turn on snapping and snap it to a point cloud. Which then asks me to give a point description (Point A). Point A will then be created and automatically inherits the X,Y,Z position of the point cloud. Then the script will loop back and asks for me to choose another point. I snap to a different point and it'll ask me for a description (Point B) and then press Enter, then it'll ask me to press enter again to confirm the Elevation (Z) value.

 

The script is working well but there is a small issue. Even though I have given 'Point A' a description, when I check the Cogo point, 'Point A' description is blank but has the correct X,Y,Z values. The very first Cogo point (Point A) doesn't ask me to press enter to confirm the Elevation, which I like because it saves time.

While 'Point B' has the description that I gave it but it will always ask me to press enter to confirm the elevation (Z) value for all the following points, which can be a pain to press enter twice after creating every point. 

 

Does anyone know why the lisp script is behaving that way? where 'Point A' automatically gets X,Y,Z position but doesn't store the point description? And 'Point B' stores the point description but will always ask me to press enter to confirm the elevation (Z value)? 

 

Is it possible to create a Cogo point by snapping to the object and it'll automatically gets the X,Y,Z value without me pressing enter to confirm the Elevation (Z) value after giving it a point description?

 

Please see attached script below. A kind user named UH shared his script with me. 

 

(defun C:UhCreate3dPoint ( / pt) 
;Points Creation >Prompt For Elevations > Manual
; Udo Huebner for Autodesk forum
(setq prevdesc "")
(prompt "UH CreatePointManual with Z Elevation")
(while (setq pt (getpoint "\nPick a Point: "))
 (if (= ""(setq desc (getstring 'T (strcat "Description <" prevdesc ">:"))))
	(setq desc prevdesc)
	;else
	(setq prevdesc desc)
 )
  (command-s  "-CreatePointManual" pt "" "")
)
(princ)
)

 

Thank you and have a good day. 

Link to post
Share on other sites

Just to clarify, the default Manual Cogo Point Creation tool in Civil 3D can't get the elevation (Z) value when snapping to an object. It will always ask you to input the Z value manually and there's no way of knowing the Z value. Hence, I'm using the lisp script to create the Cogo Point to snap to point cloud.

 

Link to post
Share on other sites

I don't have Civil 3D to test but looking at the lisp. it says ";Points Creation >Prompt For Elevations > Manual"

manually type the "-CreatePointManual" command and see what its prompting for. then modify the lisp to meet your needs. might be as simple as adding another "" IDK.

("" in lisp simulates an enter key press or picks the default option)

 

(command-s  "-CreatePointManual" pt "" "")
to
(command  "-CreatePointManual" pt "" "" "")

 

I don't see where the user description of the point is being called. so that might also be a thing to add above. I never really use command-s either.

  • Like 1
Link to post
Share on other sites

after seeing how the command wants its data try the following.

(defun C:UhCreate3dPoint (/ pt z)
;Points Creation >Prompt For Elevations > Manual
; Udo Huebner for Autodesk forum
  (setq prevdesc "")
  (while (setq pt (getpoint "\nPick a Point: "))
    (setq z (caddr pt))
    (if (= "" (setq desc (getstring 'T (strcat "Description <" prevdesc ">:"))))
      (setq desc prevdesc)
      ;else
      (setq prevdesc desc)
    )
    (command-s "-CreatePointManual" pt pause desc z) ;pause to enter point name
  )
  (princ)
)

 

Edited by mhupp
command-s might be needed.
  • Thanks 1
Link to post
Share on other sites
8 hours ago, Alexv said:

Just to clarify, the default Manual Cogo Point Creation tool in Civil 3D can't get the elevation (Z) value when snapping to an object. It will always ask you to input the Z value manually and there's no way of knowing the Z value. Hence, I'm using the lisp script to create the Cogo Point to snap to point cloud.

 

 

Hi

my language is not good So please attach a drawing explaining what is required

  • Thanks 1
Link to post
Share on other sites

Rather than use CIV3D try this it will label a point.

 

(defun c:labpts ( / pt x y z )
(command "-layer" "m" "PointsRL" "")
(setvar 'textstyle "standard")
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 8)
(while (setq ent (entsel "\npick point Enter to exit"))
(setq pt (cdr (assoc 10 (entget (car ent)))))
(setq x (car pt)
y (cadr pt)
Z (caddr pt))
(setq pt (list x y 0.0))
(command "Text" pt 2.5 0.0 (strcat "X= " (rtos x 2 3) " Y= " (rtos y 2 3)  " Z= " (rtos z 2 3)))
)
(setvar 'osmode oldsnap)
(princ)
)

 

This is write the RL of a CIV3D cogo pt.

 

(defun CIV3DPTHT ( / pt1 ht pt oldlay oldtext )

(alert "Pick CIV3D points press ESC or pick nothing to exit")
  (while (setq obj (vlax-ename->vla-object  (car (entsel))))
 ; vl 3d point convert to plain lisp 
  (setq pt1 (vlax-safearray->list (vlax-variant-value (vlax-get-property obj "Location"))))
  (setq ht (rtos (nth 2 pt1) 2 3)) ; Z val
  (setq pt (list (nth 0 pt1)(nth 1 pt1))) ; XY
  (setq oldtext (getvar "textstyle"))
  (setq oldlay (getvar "clayer"))
  (command "Layer" "n" "Pointhts" "c" 1 "Pointhts" "s" "pointhts" "") ; put text on new layer 
  ; iso 2.5 annotative text  
  (if (setvar "textstyle" "ISO2.5")
      (command "TEXT" pt 0 ht)
      (alert (strcat "The style ISO2.5 annotative does not exists" "\nplease create and run again"))
  ) 
  (setvar "textstyle" oldtext)
  (setvar "clayer" oldlay)
) ; end while 
(princ)
) ; end defun

(CIV3DPTHT)

 

I have numerous other CIV3D stuff PM me a email will send details.

  • Thanks 1
Link to post
Share on other sites

Hi everyone, thanks for all the replies. I greatly appreciate it. This is no doubt the best CAD forum I visited and I'm very glad to be apart of this community.

 

@mhupp I tried you lisp code and I successfully loaded the script inside Civil 3D. But the code doesn't run when I type in its command name 'UhCreate3dPoint',  I got an error message saying " Command: ; error: malformed list on input ". Not sure what is causing this issue. 

 

@BIGAL Thanks heaps for sharing your lisp scripts. The first script works great but it can only snaps to a point and doesn't snap to point cloud, I think each point cloud is treated as an object in Autocad/Civil 3D. I couldn't understand how the second script (CIV3DPTHT) works, I got a message 'Pick CIV3D points press ESC or pick nothing to exit'. So when I tried clicking on a point or cogo point these error messages 'Select object: ; error: bad argument type: lentityp nil' and 'Select object: ; error: ActiveX Server returned the error: unknown name: Location'. It also doesn't snap to point cloud. 

 

@hosneyalaa Thanks for the reply hosneyalaa. Your English is very good.  Here is the diagram you requested,  I hope i'm doing a good job explaining what I hope to do. Basically, I want to automatically create a Cogo point by clicking on an object (a point, end of line, middle of line, corner of block, or point cloud). Then I can give the Cogo point a point description and it has X,Y,Z position of the object I click on (using the snapping tool to snap). Please see diagram.

 

@hosneyalaa I have an old lisp script that I have been using to create the Cogo point, but the first point doesn't store the description I type in. And then it'll ask me to create another point, the second point stores the description but it also ask me to press enter for the height elevation. Please see my first post for the old lisp script. 

 

Thanks everyone for your replies. I greatly appreciated it!  Have a good day.

 

CogoPoint snapping diagram.png

Edited by Alexv
Link to post
Share on other sites
30 minutes ago, Alexv said:

@mhupp I tried you lisp code and I successfully loaded the script inside Civil 3D. But the code doesn't run when I type in its command name 'UhCreate3dPoint',  I got an error message saying " Command: ; error: malformed list on input ". Not sure what is causing this issue.

 

my bad was missing a ")"

 

(defun C:UhCreate3dPoint (/ pt z desc)
;Points Creation >Prompt For Elevations > Manual
; Udo Huebner for Autodesk forum
  (while (setq pt (getpoint "\nPick a Point: "))
    (setq z (caddr pt))
    (or (setq desc (vlax-ldata-get "Points" "Description")) (setq desc ""))
    (setq desc (getstring 'T (strcat "Description <" desc ">:")))
    (vlax-ldata-put "Points" "Description" desc)
    (command-s "-CreatePointManual" pt pause desc z) ;pause to enter point name
  )
  (princ)
)

 

Updated the code a bit to use LDATA. This has the added benefit of remembering the last description used if you save the file.

 

Edited by mhupp
  • Thanks 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...