Author Topic: Help Needed On Getsegment Lisp  (Read 1864 times)

0 Members and 1 Guest are viewing this topic.

csgoh

  • Newt
  • Posts: 176
Help Needed On Getsegment Lisp
« on: March 27, 2006, 05:52:31 AM »
Dear all,
I wrote this function whereby it returns the angle of the picked object using Stig's getsegment function.
However, on testing of my function it returns a wrong angle when picking a 3dpolyline getween point 2 and 3 as in the attached dwg. I am trying to figure where it has gone wrong but to no avail and I hope to get some input from you guys.
Code: [Select]
;; Function getsegment
;; USAGE:
;; Arguments
;; obj        -    <vla-object>
;; pt         -    <list of pick point coordinates>
;; ucs-number -    <ucs-number>
;;
(defun getSegment (obj pt ucs-number / cpt eParam stParam)
;    (cond ((setq cpt (vlax-curve-getClosestPointTo obj (trans pt ucs-number ;0)))

    (cond
      ((setq cpt (vlax-curve-getClosestPointTo obj pt))
(print "eParam ")(princ (vlax-curve-getEndParam obj))
(print "Param cpt ")(princ (vlax-curve-getParamAtPoint obj cpt))
       (setq eParam (fix (vlax-curve-getEndParam obj)))
           (if (= eParam (setq stParam (fix (vlax-curve-getParamAtPoint obj
                                             cpt))))
             (setq stParam (1- stParam))
             (setq eParam (1+ stParam))
           ) ;IF
;           (list eParam (vlax-curve-getPointAtParam obj stParam)
;                        (vlax-curve-getPointAtParam obj eParam))
           (list (vlax-curve-getPointAtParam obj stParam)
                 (vlax-curve-getPointAtParam obj eParam))
      )
    ) ;COND
  ) ;GETSEGMENT

;; wg:GetEntityAngle
;; Argument: Entity
;; Returns: angle of the selected entity at its selection point in radians.
;; USAGE:
;; (wg:GetEntityAngle entity)
(defun wg:GetEntityAngle( ent ucs-number
                         / ent obj obj_ent pt_lst ang ptend ptstart)
            (setq obj (vlax-ename->vla-object (car ent))
                  obj_typ (vlax-get-property obj 'ObjectName))
        (cond
         ((= obj_typ "AcDb3dPolyline")
          (if (setq pt_lst (getSegment obj (last ent) ucs-number))
           (progn
(print "pt_lst ")(princ pt_lst)
               (angle (trans (car pt_lst) 0 ucs-number )
                      (trans (cadr pt_lst) 0 ucs-number)
               )
           );progn
          )
         )
         ((= obj_typ "AcDbPolyline")
          (if (setq pt_lst (getSegment obj (last ent) ucs-number))
               (angle (trans (car pt_lst) 0 ucs-number )
                      (trans (cadr pt_lst) 0 ucs-number)
               )
          );if
         )
         ((= obj_typ "AcDbLine")
          (vlax-get-property obj 'Angle)
         )

         ((= obj_typ "AcDbText")
          (vlax-get-property obj 'Rotation)
         )
         ((= obj_typ "AcDbMText")
          (vlax-get-property obj 'Rotation)
         )
         ((= obj_typ "AcDbArc")
          (setq ptend (vlax-safearray->list
                        (vlax-variant-value
                          (vla-get-EndPoint obj)))
                ptstart (vlax-safearray->list
                          (vlax-variant-value
                            (vla-get-StartPoint obj)))
          )
           (angle ptstart ptend)
         )     
         (T
;           (dos_beep 3)
           (alert "That's not an entity I deal with")
           nil
         )
        ) ;second cond
); wg:GetEntityAngle
 
(defun c:test ()
(vl-load-com)
(setq e (entsel "\nSelect a 3dpolyline ")
      ucs-number 0
)
 (if e
  (progn
   (if (setq ang (wg:GetEntityAngle e ucs-number))
     (setq txtsudut ang)
   );if
 (print "ang ")(princ ang)
  );progn
 );if
(princ)
);test

The results if I pick between 0 & 1
Command: test

Select a 3dpolyline
"eParam " 3.0
"Param cpt " 0.0
"pt_lst " ((21.002 19.665 10.0) (26.2639 24.409 20.0))
"ang " 0.733674

and 2 & 3 are correct.
Command:  TEST
Select a 3dpolyline
"eParam " 3.0
"Param cpt " 2.97225
"pt_lst " ((35.6916 24.9199 30.0) (42.0498 21.4167 0.0))
"ang " 5.77959

However if I pick between point 1 & 2 it returns a wrong angle.
Command:  TEST
Select a 3dpolyline
"eParam " 3.0
"Param cpt " 2.91552
"pt_lst " ((35.6916 24.9199 30.0) (42.0498 21.4167 0.0))
"ang " 5.77959
By right, the angle should be 0.0541372.

I tested this function in acad 2005 and acadmap 2004 in win xp sp2.
Thanks in advance.

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Re: Help Needed On Getsegment Lisp
« Reply #1 on: March 27, 2006, 11:13:48 AM »
Hi csgoh,
The problem is not so much with Stig's routine, but with the point passed to it.....(entsel) always has a Z value equal to the current Elevation, so the end point of the 3d poly happened to be the "closestpointto" the selected point. Adding a (osnap pt near) solves this:
Code: [Select]
......
((= obj_typ "AcDb3dPolyline")
          (if (setq pt_lst (getSegment obj (osnap (last ent) "near") ucs-number)
.....
Command: test
Select a 3dpolyline
"eParam " 3.0
"Param cpt " 1.46137
"pt_lst " ((26.2639 24.409 20.0) (35.6916 24.9199 30.0))
"ang " 0.0541372

HTH,
Jeff

csgoh

  • Newt
  • Posts: 176
Re: Help Needed On Getsegment Lisp
« Reply #2 on: March 27, 2006, 07:22:04 PM »
Jeff
Thanks.

csgoh