Author Topic: Pline endpoint/angle question  (Read 7756 times)

0 Members and 1 Guest are viewing this topic.

Guest

  • Guest
Pline endpoint/angle question
« on: December 05, 2006, 01:45:55 PM »
I'm sure there's gonna be some VLAX-blah blah blah involved with this (which I know little to none about) but.... I would like to be able to select a pline and get the angles of both ends of the pline.

Help!!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Pline endpoint/angle question
« Reply #1 on: December 05, 2006, 01:53:50 PM »
I think I might not be understanding, but I would write one that would create an associated list of the segment number, and the angle.  Does that should like it would be useful?  I think you have to step through it no matter what to get to the end, so making a list along the way would do any harm.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #2 on: December 05, 2006, 01:56:43 PM »
See is this can give you a start:

Code: [Select]
(setq curve (car (entsel "\nSelect polyline: ")))
(setq end_param (vlax-curve-getendparam ename))
(if (>= end_param 2.0)
  (progn
    (setq start_param (vlax-curve-getstartparam ename))

    (setq a (vlax-curve-getpointatparam curve start_param))
    (setq b (vlax-curve-getpointatparam curve (1+ start_param)))
    (setq ang1 (angle a b))

    (setq b (vlax-curve-getpointatparam curve end_param))
    (setq a (vlax-curve-getpointatparam curve (1- end_param)))
    (setq ang2 (angle a b))
    ))

I did it on the fly.... so be careful...

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #3 on: December 05, 2006, 02:02:39 PM »
Luis:
I get this at the command line: Select polyline: ; error: unable to get ObjectID: nil


Code: [Select]
(defun C:PLEnd ( / curve end_param start_param a b ang1 ang2)
   (vl-load-com)
   (setq curve (car (entsel "\nSelect polyline: ")))
   (setq end_param (vlax-curve-getendparam ename))
   (if (>= end_param 2.0)
      (progn
         (setq start_param (vlax-curve-getstartparam ename))
         (setq a (vlax-curve-getpointatparam curve start_param))
         (setq b (vlax-curve-getpointatparam curve (1+ start_param)))
         (setq ang1 (angle a b))

         (setq b (vlax-curve-getpointatparam curve end_param))
         (setq a (vlax-curve-getpointatparam curve (1- end_param)))
         (setq ang2 (angle a b))
      )
   )
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Pline endpoint/angle question
« Reply #4 on: December 05, 2006, 02:04:51 PM »
Matt,

  There is a mixture of variable naming for the ename in Luis's code.  You need to choose one name for the variable, either 'curve' or 'ename'.  I think it will work after that small change.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #5 on: December 05, 2006, 02:10:04 PM »
See... that happens when you do code from memory....

Code: [Select]
(defun C:PLEnd (/ curve end_param start_param a b ang1 ang2)
  (vl-load-com)
  (setq curve (car (entsel "\nSelect polyline: ")))
  (setq end_param (vlax-curve-getendparam curve))
  (if (>= end_param 2.0)
    (progn
      (setq start_param (vlax-curve-getstartparam curve))
      (setq a (vlax-curve-getpointatparam curve start_param))
      (setq b (vlax-curve-getpointatparam curve (1+ start_param)))
      (setq ang1 (angle a b))

      (setq b (vlax-curve-getpointatparam curve end_param))
      (setq a (vlax-curve-getpointatparam curve (1- end_param)))
      (setq ang2 (angle a b))

      )
    )
  )

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #6 on: December 05, 2006, 02:14:11 PM »
I noticed that after I posted.  I changed all of the "curve"s to "ename"s and it appears to be working (so far).  When I'm done, I'll post what I've done.

Basically I'm trying to create a program that will automatically add "tick" marks to the ends of contours (prior to actually turning them into contour objects).  The way I'm doing it now is not the easiest.

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #7 on: December 05, 2006, 02:14:54 PM »
Quote
See... that happens when you do code from memory....
I still appreciate it.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Pline endpoint/angle question
« Reply #8 on: December 05, 2006, 02:19:11 PM »
I have one that will insert a break '~' at the end of the object selected, line, pline, arc.  If you think it could be helpful I could post it.

Edit: Item created is a pline.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #9 on: December 05, 2006, 02:19:50 PM »
Quote
See... that happens when you do code from memory....
I still appreciate it.

Great.

...
It can be easy just to do it globally - to find all the endpoints and add the terminator :)

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #10 on: December 05, 2006, 02:25:16 PM »
I have one that will insert a break '~' at the end of the object selected, line, pline, arc.  If you think it could be helpful I could post it.

Sure, post away... I'm always (well, maybe not ALWAYS) willing to learn something new.

Thanks!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Pline endpoint/angle question
« Reply #11 on: December 05, 2006, 02:28:19 PM »
Here you go.
Code: [Select]
(defun c:IBM (/ Ent Obj EntData EntType Lay InsPt tmpPt1 tmpPt2 tmpPt3 tmpSS
                pt3 pt4 pt5 pt6 ang0 ang1 ang2 ang3 ang4 clay osmd ocmd)
; Draws break mark at the end of and object

(setq osmd (getvar "osmode")
 ocmd (getvar "cmdecho")
 clay (getvar "clayer")
)
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(if (not GlbScale)
 (setq GlbScale 1.0)
)
(if (setq Ent (entsel "\n Select object near endpoint to draw break symbol: "))
 (progn
  (princ "\n Enter scale if different <")
  (princ (rtos GlbScale 4 5))
  (setq sc1 (getreal ">: "))
  (if (not sc1)
   (setq sc1 GlbScale)
   (setq GlbScale sc1)
  )
  (setq ps1 (* sc1 0.02))
  (setq ps2 (* sc1 0.045))
  (setq EntData (entget (car Ent)))
  (setq Obj (vlax-ename->vla-object (car Ent)))
  (setq EntType (value 0 EntData))
  (setq Lay (value 8 EntData))
  (setq tmpPt1 (vlax-curve-GetStartPoint Obj))
  (setq tmpPt2 (vlax-curve-GetEndPoint Obj))
  (setq tmpPt3 (cadr Ent))
  (if (< (distance tmpPt3 tmpPt1) (distance tmpPt3 tmpPt2))
   (setq InsPt tmpPt1)
   (setq InsPt tmpPt2)
  )
  (if (= EntType "ARC")
   (progn
    (setq ang0 (angle (value 10 EntData) InsPt))
    (setq ang1 (+ ang0 (angtof "155.4" 0)))
    (setq ang2 (+ ang0 (angtof "200.38" 0)))
    (setq ang3 (+ ang0 (angtof "335.4" 0)))
    (Setq ang4 (+ ang0 (angtof "380.38" 0)))
    (setq pt3 (polar InsPt ang1 ps1))
    (setq pt4 (polar InsPt ang2 ps2))
    (setq pt5 (polar InsPt ang3 ps1))
    (setq pt6 (polar InsPt ang4 ps2))
   )
   (progn
    (setq ang0 (angle tmpPt1 tmpPt2))
    (setq ang1 (+ ang0 (angtof "65.4" 0)))
    (setq ang2 (+ ang0 (angtof "110.38" 0)))
    (setq ang3 (+ ang0 (angtof "245.4" 0)))
    (Setq ang4 (+ ang0 (angtof "290.38" 0)))
    (setq pt3 (polar InsPt ang1 ps1))
    (setq pt4 (polar InsPt ang2 ps2))
    (setq pt5 (polar InsPt ang3 ps1))
    (setq pt6 (polar InsPt ang4 ps2))
   )
  )
  (setvar "clayer" Lay)
  (command "_.arc" InsPt pt3 pt4)
  (setq tmpSS (ssadd (entlast)))
  (command "_.arc" InsPt pt5 pt6)
  (command "_.pedit" (entlast) "_y" "_j" tmpSS "" "")
 )
 (prompt "\n Nothing selected. ")
)
(setvar "clayer" clay)
(setvar "osmode" osmd)
(command "_.undo" "_end")
(setvar "cmdecho" ocmd)
(princ)
)
;----------------------------------------------------------------------------------
(defun VALUE (num ent /)
  (cdr (assoc num ent))
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #12 on: December 05, 2006, 02:41:20 PM »
Matt;

See if this quick routine, does the job.

Just replace "TICK" with your own block, must be drawn like:  |  and the insertion the mid point of the tick

Code: [Select]
(defun insertblock
    (insertionpoint      name xscale
     yscale zscale      rotation space
     / vla_insert)
  (if (not (vl-catch-all-error-p
     (setq vla_insert
    (vl-catch-all-apply
      'vla-insertblock
      (list space
    (vlax-3d-point insertionpoint)
    name
    xscale
    yscale
    zscale
    rotation)))))
    vla_insert))

(defun C:ADDT  (/ ss p1 p2 s pline txt)
  (prompt "\nSelect polylines items...")
  (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
    (progn
      (mapcar
(function (lambda (curve)
    (setq obj (vlax-ename->vla-object curve))
    (setq space (vla-objectidtoobject
  (vla-get-database obj)
  (vla-get-ownerid obj)))
    (setq end_param (vlax-curve-getendparam curve))
    (if (>= end_param 2.0)
      (progn
(setq start_param
       (vlax-curve-getstartparam curve))
(setq a (vlax-curve-getpointatparam
  curve
  start_param))
(setq b (vlax-curve-getpointatparam
  curve
  (1+ start_param)))
(setq ang1 (angle a b))
(insertblock
  a "TICK" 1.0 1.0 1.0 ang1 space)
(setq b (vlax-curve-getpointatparam
  curve
  end_param))
(setq a (vlax-curve-getpointatparam
  curve
  (1- end_param)))
(setq ang2 (angle a b))
(insertblock
  b "TICK" 1.0 1.0 1.0 ang2 space)))))
(vl-remove-if
  (function listp)
  (mapcar (function cadr) (ssnamex ss))))))
  (princ))
(princ)

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #13 on: December 05, 2006, 02:49:31 PM »
Matt;

See if this quick routine, does the job.

Just replace "TICK" with your own block, must be drawn like:  |  and the insertion the mid point of the tick

Well that's just slicker than dog$&% on wet leaves!!!  Just gotta do a little tweaking to have the tick scale according to the current ltscale.

You guys are good!!  Thanks!

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #14 on: December 05, 2006, 02:55:16 PM »
Well that's just slicker than dog$&% on wet leaves!!!  Just gotta do a little tweaking to have the tick scale according to the current ltscale.

You guys are good!!  Thanks!

:)

Where reads the calls for insertblock, just replace the 1.0's with the return of LTSCALE and rock and roll:

Quote
(insertblock a "TICK" 1.0 1.0 1.0 ang1 space)