Author Topic: Pline endpoint/angle question  (Read 7625 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)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Pline endpoint/angle question
« Reply #15 on: December 05, 2006, 03:32:38 PM »
To get the angle of the polyline at each end perhaps this will do it.
This handles arc segments & can be used with splines.

Code: [Select]
  (vl-load-com)
  (setq curve (car (entsel "\nSelect polyline: ")))
  (setq end_param (vlax-curve-getendparam curve))
  (setq startang (angle '(0 0) (vlax-curve-getFirstDeriv curve 0.05)))
  (setq endang (angle '(0 0) (vlax-curve-getFirstDeriv curve (- end_param 0.05))))
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #16 on: December 05, 2006, 04:12:12 PM »
Quote
Where reads the calls for insertblock, just replace the 1.0's with the return of LTSCALE and rock and roll:

You're making this WAAAAAY too easy for me.   And I thank you for that!

Who's #1?? YOU are!


LE

  • Guest
Re: Pline endpoint/angle question
« Reply #17 on: December 05, 2006, 05:18:37 PM »
!

 :oops:

Thanks.

I am playing (writing right now as part of my learning phase) with the routine, now with C#, as soon as I know how to use the insert method, I will post it, and see if runs faster....

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Pline endpoint/angle question
« Reply #18 on: December 05, 2006, 05:38:04 PM »
I am playing (writing right now as part of my learning phase) with the routine, now with C#, as soon as I know how to use the insert method, I will post it, and see if runs faster....
I think I remembering reading on one site that you have to create all the atrributes associated with the blocks definition when using C#.  FYI....
« Last Edit: December 05, 2006, 05:39:58 PM by T.Willey »
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 #19 on: December 05, 2006, 07:05:00 PM »
Thank you Tim;

Yes I am aware about that, have read a LOT... anyway this does not have attributes and I have open a new topic here:

http://www.theswamp.org/index.php?topic=13836.msg166838#msg166838

Just for fun.

sinc

  • Guest
Re: Pline endpoint/angle question
« Reply #20 on: December 06, 2006, 11:15:36 AM »
To get the angle of the polyline at each end perhaps this will do it.
This handles arc segments & can be used with splines.

Code: [Select]
  (vl-load-com)
  (setq curve (car (entsel "\nSelect polyline: ")))
  (setq end_param (vlax-curve-getendparam curve))
  (setq startang (angle '(0 0) (vlax-curve-getFirstDeriv curve 0.05)))
  (setq endang (angle '(0 0) (vlax-curve-getFirstDeriv curve (- end_param 0.05))))

The only thing that I might do differently is use the distance commands to get the end angle.  For example, you could get the parameter for the point that is 0.001 from the end of the line, then get the First Derivative of that.

The problem with subtracting parameters is that the size varies in polylines, depending on the length of the segment.  So it's possible that your .05 parameter might be 1, 10, or 20 feet from the end of the line.
« Last Edit: December 06, 2006, 11:16:50 AM by sinc »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Pline endpoint/angle question
« Reply #21 on: December 06, 2006, 12:07:45 PM »
I was perplexed as to how best to approach that aspect. I got the vlax-curve-getFirstDeriv idea from one of your
previous posts. The problem with distance is that the opposite may be true. There could be very little distance between
the two parameters. I suppose you would have to do some sort of distance checking to be sure of what you were dealing
with before settling on a value to use for the distance.

I was just being lazy with my 0.05 parameter & hoping it would be OK. :)
I did consider a check of the value but was holding off to see if anyone would actually use it.


Glad to see someone was paying attention.  8-)
« Last Edit: December 06, 2006, 12:08:48 PM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #22 on: December 06, 2006, 01:31:11 PM »
Okay... I've got one other question...  How do you obtain the layer name of the pline??  Right now I'm using this:

Code: [Select]
(setq objLay (cdr (assoc 8 (entget curve))))
But what's the vlisp way?

Thanks again!

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #23 on: December 06, 2006, 01:50:07 PM »
Glad to see someone was paying attention.  8-)

Alan;

I ALWAYS put attention, and will try to provide a solution, every time I can.

I will do your recommendation into the new C# routine approach I posted in the NET forum, once I get a chance.

Cheers.

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #24 on: December 06, 2006, 01:51:47 PM »
Code: [Select]
(setq objLay (cdr (assoc 8 (entget curve))))
But what's the vlisp way?


Matt;

Look into VLA-GET-LAYER and VLA-PUT-LAYER functions.

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #25 on: December 06, 2006, 02:05:19 PM »
Quote
Matt;

Look into VLA-GET-LAYER and VLA-PUT-LAYER functions.

WHAT??!?!?!  You expect ME to do some work now??!?  Sheesh... the nerve of some people.  ;)


I'll look into that and thanks again.  (and if you post back with the solution, I'm NOT gonna read it).

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #26 on: December 06, 2006, 02:08:25 PM »
(and if you post back with the solution, I'm NOT gonna read it).

OK.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Pline endpoint/angle question
« Reply #27 on: December 06, 2006, 02:23:53 PM »
Glad to see someone was paying attention.  8-)

Alan;

I ALWAYS put attention, and will try to provide a solution, every time I can.

I will do your recommendation into the new C# routine approach I posted in the NET forum, once I get a chance.

Cheers.
I know it would be hard to sneak anything past you Luis. :-)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Guest

  • Guest
Re: Pline endpoint/angle question
« Reply #28 on: December 06, 2006, 02:24:05 PM »
[Quagmire - Family Guy]Heh heh.... Alright![/Quagmire]

(setq objLay (vla-get-layer (vlax-ename->vla-object curve)))

SWEEEET!!!

LE

  • Guest
Re: Pline endpoint/angle question
« Reply #29 on: December 06, 2006, 06:29:07 PM »
I know it would be hard to sneak anything past you Luis. :-)

I have attached the command ADDTICKS (just for A2007), if anyone would like to try it - for lwpolylines and splines.

HTH

http://www.theswamp.org/index.php?topic=13836.msg167054#msg167054