Jump to content

Autolisp move function


johnm1011

Recommended Posts

I am trying to write a LISP that will take the Z dimension of Points 1,2 & 3 and average them, then use that averaged number and move the forth point (a COGO point) that didtance in the z axis. I essentially want to move the COGO which has a Z value of 0 to the height of the average "Z" of the first three points. Hope that makes sense!

 

Here's what I have got so far:

 

(defun C:za (/ pt1 pt2 pt3 z1 z2 z3 z4 zdev1 ss x1 y1 pta ptb )
 (setq pt1 (getpoint "\n Point 1: ")) 
 (setq pt2 (getpoint "\n Point 2: "))
 (setq pt3 (getpoint "\n Point 3: "))
 (setq z1 (caddr pt1))
 (setq z2 (caddr pt2))
 (setq z3 (caddr pt3))
 (setq zdev1 (/ (+ z1 z2 z3) 3))
 (princ (rtos zdev1 2 2))
 (setq ss (ssget "_+.:E:S" '((0 . "AECC_COGO_POINT"))))
 (setq pta (getpoint "Basepoint: "))			;;Basepoint of forth point      so i can use the X and Y coordinates
 (setq x1 (car pt1))
 (setq y1 (cadr pt1))
 (setq z4 (/ (+ z1 z2 z3) 3))
 (setq ptb (x1 y1 zdev1))				;;trying to add in the averaged Z to set pt2
 (command "move" ss "" pt1 pt2)
 (princ)  
)

 

 

Please help!

Thanks

John

Edited by rkmcswain
added [CODE] tags
Link to comment
Share on other sites

Please help!

Thanks

John

 

(defun C:za (/ pt1 pt2 pt3 z1 z2 z3 z4 zdev1 ss x1 y1 pta ptb )
 (setq pt1 (getpoint "\n Point 1: ")) 
 (setq pt2 (getpoint "\n Point 2: "))
 (setq pt3 (getpoint "\n Point 3: "))
 (setq z1 (caddr pt1))
 (setq z2 (caddr pt2))
 (setq z3 (caddr pt3))
 (setq zdev1 (/ (+ z1 z2 z3) 3))
 (princ (rtos zdev1 2 2))
 (setq ss (ssget "_+.:E:S" '((0 . "AECC_COGO_POINT"))))
 (setq pta (getpoint "Basepoint: "))			
 (setq x1 (car [color="red"]pta[/color]))
 (setq y1 (cadr [color="red"]pta[/color]))
[color="gray"];;;  (setq z4 (/ (+ z1 z2 z3) 3))[/color]
 (setq ptb ([color="blue"]list[/color] x1 y1 zdev1))				
 (command "move" ss "" [color="red"]pta ptb[/color])
 (princ)  
)

sorry, im not so clear. here's are my understanding

1.you just want to move the cogo_point to average elevation? its x,y position unchanged? only z?

2.only ssget single?

3.base point (4th point) should not move to 5th point?

4.pta = ptb for x,y ? the difference ptb's z= average of p1,p2,p3 ?

Link to comment
Share on other sites

I am trying to write a LISP that will take the Z dimension of Points 1,2 & 3 and average them, then use that averaged number and move the forth point (a COGO point) that didtance in the z axis. I essentially want to move the COGO which has a Z value of 0 to the height of the average "Z" of the first three points. Hope that makes sense!

 

Here's what I have got so far:

 

(defun C:za (/ pt1 pt2 pt3 z1 z2 z3 z4 zdev1 ss x1 y1 pta ptb )
 (setq pt1 (getpoint "\n Point 1: ")) 
 (setq pt2 (getpoint "\n Point 2: "))
 (setq pt3 (getpoint "\n Point 3: "))
 (setq z1 (caddr pt1))
 (setq z2 (caddr pt2))
 (setq z3 (caddr pt3))
 (setq zdev1 (/ (+ z1 z2 z3) 3))
 (princ (rtos zdev1 2 2))
 (setq ss (ssget "_+.:E:S" '((0 . "AECC_COGO_POINT"))))
 (setq pta (getpoint "Basepoint: "))			;;Basepoint of forth point      so i can use the X and Y coordinates
 (setq x1 (car pt1))
 (setq y1 (cadr pt1))
 (setq z4 (/ (+ z1 z2 z3) 3))
 (setq ptb (x1 y1 zdev1))				;;trying to add in the averaged Z to set pt2
 (command "move" ss "" pt1 pt2)
 (princ)  
)

 

Give this a try:

 

(vl-load-com)

(defun c:MoveCogoToAverageElevation (/ *error* osnapz pt1 pt2 pt3 average acDoc)

 (defun *error* (msg)
   (and osnapz (setvar 'osnapz osnapz))
   (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
     (setq osnapz (getvar 'osnapz))
     (setvar 'osnapz 0)
     (setq pt1 (getpoint "\nSpecify first point: "))
     (not (initget 32))
     (setq pt2 (getpoint pt1 "\nSpecify second point: "))
     (not (initget 32))
     (setq pt3 (getpoint pt2 "\nSpecify tertiary point: "))
     (princ
       (strcat
         "\nSelect COGO points to move to "
         (rtos
           (setq average
                  (/ (apply
                       '+
                       (mapcar (function (lambda (x) (caddr x)))
                               (list pt1 pt2 pt3)
                       )
                     )
                     3
                  )
           )
           2
           2
         )
         " average elevation: "
       )
     )
     (princ)
     (ssget "_:L" '((0 . "AECC_COGO_POINT")))
   )
    (progn
      (vla-startundomark
        (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
      )
      (vlax-for x (vla-get-activeselectionset acDoc)
        (vla-put-elevation x average)
      )
    )
 )
 (*error* nil)
)

Link to comment
Share on other sites

1) Yes

2) i believe so if you mean only select the one COGO point

3) 4th point is the ssget to select the COGO point and the fifth was to click on the COGO so that i could use its "X" & "Y" coordinates

4) YES

Link to comment
Share on other sites

sorry, im not so clear.

 

COGO Points are something that we use in Civil 3D, they help us with topography, identifying structures or critical elevations, and even building Surfaces. Some Properties, Methods, and Events are exposed to LISP, and some are not.

 

If you have Civil 3D at your disposal for testing, coding, etc. and you code in LISP, then you'll find vlax-Dump-Object function to be of great use. If you use Civil 3D for production, and are beginning to delve into the COM/.NET side of things (not just Visual LISP), then I'd also suggest you add the MgdDbg and SnoopC3D plug-ins to your toolbox.

 

Cheers

Link to comment
Share on other sites

Black box,

I pretty new to autolisp and i did notice you use "vla-" in the LISP you wrote for me. Whats vla?

 

Thanks

 

That's a loaded question. :)

 

The short answer, is that LISP is generally referred to providing two different 'flavors'... vanilla LISP (aka AutoLISP) is the original implementation that AutoCAD came with, and later Visual LISP (ActiveX COM API like VBA) was added in order to extend functionality, etc.

 

Particularly when you're new to LISP, this topic can be confusing, but once you grasp the concepts at play, it's usually pretty simple to build on... There is a difference between VL-, VLA-, VLAX-, etc. prefixes, which David does a good job of clarifying here.

 

HTH

Link to comment
Share on other sites

Also, the two plug-ins you mentioned what are their purpose. I use C3D mainly for survey purposes (layout of structures, as-builting, and so on) would they be of any use to me.

Link to comment
Share on other sites

Also, the two plug-ins you mentioned what are their purpose. I use C3D mainly for survey purposes (layout of structures, as-builting, and so on) would they be of any use to me.

 

MgdDbg, and SnoopC3D are developer tools that make it easy to cull a drawing, or object for it's .NET Properties, monitor .NET Events, etc.... If you're new to LISP, you may not benefit from them until you're ready to step up into .NET API... However, you're always welcome to start with .NET API from the outset, in which case this old thread may be of use in getting started.

 

If the latter, you might also be interested in becoming an AUGI Professional Member, as it comes with a FREE Autodesk Developer Network (ADN) Standard Membership (saving you $1400). :thumbsup:

 

Cheers

Link to comment
Share on other sites

COGO Points are something that we use in Civil 3D, they help us with topography, identifying structures or critical elevations, and even building Surfaces. Some Properties, Methods, and Events are exposed to LISP, and some are not.

 

If you have Civil 3D at your disposal for testing, coding, etc. and you code in LISP, then you'll find vlax-Dump-Object function to be of great use. If you use Civil 3D for production, and are beginning to delve into the COM/.NET side of things (not just Visual LISP), then I'd also suggest you add the MgdDbg and SnoopC3D plug-ins to your toolbox.

 

Cheers

 

Thank you mr.BlackBox,

as im not using C3D, in normal acad aecc_cogo_point is just a proxy_entity. so property elevation not available. Besides, i got this AcDbZombieEntity :lol:

 

; IAcadEntity: AutoCAD Entity Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00d077b4>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 0912da68>
;   Handle (RO) = "19E21"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 0d5a34f4>
;   Layer = "LEVEL"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   ObjectID (RO) = 2112328456
;   ObjectName (RO) = "[color="red"]AcDbZombieEntity[/color]"
;   OwnerID (RO) = 2113953040
;   PlotStyleName = "ByLayer"
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 0d5a3040>
;   Visible = -1

 

 

1) Yes

2) i believe so if you mean only select the one COGO point

3) 4th point is the ssget to select the COGO point and the fifth was to click on the COGO so that i could use its "X" & "Y" coordinates

4) YES

Just refer vla- due to COGO is a different method.

Link to comment
Share on other sites

Like Blockbox as soon as I saw AEcc-point I though just PUT elevation not move as this can give an error. Also not sure here but divide 3 v's 3.0 ? Always ensures real calcs.

 

Here is another example of manipulating Cogo Points.

 

; rotate civ3d point example
; Rotate civ 3d points
; By BIG AL NOV 2014
(defun dtr (a)
(* pi (/ a 180.0))
)
(defun CIV3DPTROT ( / obj oldtext oldlay xyz pt1 ht pt)
(alert "Pick CIV3D points press ESC or pick nothing to exit")
(setq ang (dtr (getreal "\nEnter Angle")))
(while (setq obj (vlax-ename->vla-object  (car (entsel))))
(vlax-put-property obj "Rotation" ang )
)
) ; end defun

(CIV3DPTROT)
.5707) ;approx 90deg 45 is 0.7854
) 

and

; Lable individual Cogo point hts as text
; By BIGAL
;
(defun CIV3DPTHT ( / obj oldtext oldlay xyz pt1 ht pt)
 (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 
 ; 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)

Edited by BIGAL
Updated rotate3d
Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...