Author Topic: LWPOLYLINE - how to capture  (Read 3034 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
LWPOLYLINE - how to capture
« on: August 25, 2006, 06:14:53 PM »
I was hoping this would be a quick question, but from the looks of viva's post, "Capturing the polyline in orderwise",
http://www.theswamp.org/index.php?topic=12046.0
I'm beginning to think it's going to be a drawn-out process by the comments made.
I don't wanna be a thread-thief so, here's my question.

I have the association for a line and have found the X of start and X of end (assoc 10 & 11).
Code: [Select]
  (setq jln (ssget '((0 . "LINE")))))
  (setq num 0)
  (setq njln (sslength jln))
  (while (< num njln)
    (progn
      (setq lnx1 (cdr (assoc 10 (entget (ssname jln num))))
            lny1 (cdr (assoc 11 (entget (ssname jln num))))
            lyr1 (cdr (assoc  8 (entget (ssname jln num))))
            clr1 (cdr (assoc 62 (entget (ssname jln num))))

How can I find the similar for an lwpolyline ??
I need to find the start of and the end of or the first vertex and second vertex of a pline.

I need to tie it into this code, so I can select plines & lines together and have the info for both.

Thanks.

Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: LWPOLYLINE - how to capture
« Reply #1 on: August 25, 2006, 06:31:32 PM »
A couple quick functions, first the activex version --

Code: [Select]
(defun GetLwPolyLineCoords ( lwPolyLineObject )
    ;;  the caller is fully responsible for
    ;;  suppyling a valid lwPolyLine object
    (   (lambda ( coords / result )
            (repeat (/ (length coords) 2)
                (setq
                    result (cons (list (cadr coords) (car coords)) result)
                    coords (cddr coords)                   
                )
            )
            result
        )
        (reverse (vlax-get lwPolyLineObject 'Coordinates))
    )   
)

and then an old style dxf version ...

Code: [Select]
(defun GetLwPolyLineCoords ( lwPolyLineEntity )
    ;;  the caller is fully responsible for
    ;;  suppyling a valid lwPolyLine entity
    (mapcar 'cdr
        (vl-remove-if-not
           '(lambda (pair) (eq 10 (car pair)))
            (entget lwPolyLineEntity)
        )   
    )   
)

Example (using activex version) --

Code: [Select]
    (setq coords (GetLwPolyLineCoords lwPolyLineObject))
   
    ;;  might return

    (   (9.79343 10.1256)
        (17.2641 5.24297)
        (24.3978 4.51338)
        (33.1605 5.35521)
        (40.1818 9.39599)
        (43.5521 16.5235)
        (42.3725 22.3602)
        (33.3851 25.952)
        (21.0276 25.6152)
        (14.8488 22.4163)
        (12.0964 18.9928)
        (9.56874 13.998)
    )
   
    ;;  the first vertex
   
    (car coords) => (9.79343 10.1256)
   
    ;;  second vertex
   
    (cadr coords) => (17.2641 5.24297)
   
    ;;  last
   
    (last coords) => (9.56874 13.998)
   
    ;;  etc.

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: LWPOLYLINE - how to capture
« Reply #2 on: August 25, 2006, 08:57:49 PM »
Another:
Code: [Select]
(defun getlwpolylinecoords (ent / idx pt result)
  (setq idx -1)
  (while (setq pt  (vlax-curve-getpointatparam ent (setq idx (1+ idx))))
     (setq result (cons pt result))
  )
  (reverse result)
)

PS one more:
Code: [Select]
(defun getlwpolylinecoords (ent / idx result)
  (setq idx (1+ (vlax-curve-getendparam ent)))
  (while (not (zerop idx))
    (setq result (cons (vlax-curve-getpointatparam ent (setq idx (1- idx))) result))
  )
  result
)
« Last Edit: August 25, 2006, 11:32:36 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.

sepperl

  • Guest
Re: LWPOLYLINE - how to capture
« Reply #3 on: August 26, 2006, 02:32:08 AM »
Be careful !
There is a little difference betwen the functions from CAB and MP !

The functions from MP returns the Coordinates in ObjectCoordinateSystem (vlax-get... returns 2D-Points equal to entget...).
CAB ones returns the Coordinates in WCS (vlax-curve... returns 3D-Points).

When you work only in 2D the results are quite similar. (X and Y are equal, only Z is missing in MP's result)

In 3D there is a significant difference in the Coordinates, when the Pline is not parallel to WCS.

This caused al lot of trouble in my own programms. I mixed vlax-curve.... funtions with vlax-get... functions.
In 2D it worked fine (thought that 3D will never be used), but now 3D is used and I have to rewrite all my Pline-Functions... :x

...only a hint...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: LWPOLYLINE - how to capture
« Reply #4 on: August 26, 2006, 08:56:30 AM »
Thanks sepperl for the good tip. 
So many of us work in a 2d world and forget we live in a 3d world. :)

Welcome, I see you have been a member for a while but mostly lurking. <not a bad thing, I do it myself>
Do you have time to share the 3d techniques you are know using to handle points?
« Last Edit: August 26, 2006, 08:59:09 AM 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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: LWPOLYLINE - how to capture
« Reply #5 on: August 26, 2006, 10:08:11 AM »
Very good point sepperl, thank you for the sanity check.

If 3D WCS points are desired I'd pen it like so --

Code: [Select]
(defun GetLwPolyLineCoords ( lwPolyLineEntity / i result)

    (setq i (1+ (vlax-curve-getendparam lwPolyLineEntity)))

    (repeat (cdr (assoc 90 (entget lwPolyLineEntity)))
        (setq result
            (cons
                (vlax-curve-getpointatparam
                    lwPolyLineEntity
                    (setq i (1- i))
                )
                result
            )
        )
    )
)

Wicked headache today, hope the above is w/out errors. Cheers.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

sepperl

  • Guest
Re: LWPOLYLINE - how to capture
« Reply #6 on: August 26, 2006, 03:12:35 PM »
@CAB
I don't have any 3D techiques to handle points yet, because I noticed this 'error' only a few days ago.
At the moment this causes a lot of headache to me.(Hi MP :lol: )
I have to fix a lot of pline-functions (many Library-funcs) !

I think about to write  'my own' vlax-curve...functions, which return the coordinates in OCS, because all other functions like entget or vlax... return in OCS
Simply call the vlax-curve...function and then trans the point to OCS.
Then replace the 'old' functioncalls with the 'new' (find and replace in editor)
But for now, I'm not sure if this is the 'overall' solution...

Example (untested):
Code: [Select]
(defun vlax*-curve-getstartpoint (obj /)
  (reverse
    (cdr
      (reverse (trans (vlax-curve-getstartpoint obj) 0 (vlax-vla-object->ename obj)))
    )
  )
)

About lurking:
It is true, I browse often  thru the forum without posting, because I'm not used to write English text (perhaps you noticed ?).
I'm form Bavaria, so English is not my prefred language.

Greetings...

« Last Edit: August 26, 2006, 03:13:49 PM by sepperl »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: LWPOLYLINE - how to capture
« Reply #7 on: August 26, 2006, 03:46:20 PM »
Thanks for the example.
You may find this of interest too.
http://www.theswamp.org/index.php?topic=3836.msg46404#msg46404
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: LWPOLYLINE - how to capture
« Reply #8 on: August 26, 2006, 04:23:20 PM »
For all Elevation and Extrusion direction...
Code: [Select]
(defun c:lw-coord-lst (/ E EN N)
  ;;(c:lw-coord-lst)
  (if (and(setq en (car (entsel)))
          (=(cdr(assoc 0 (setq  en (entget en))))"LWPOLYLINE"))
    (setq n  (cdr (assoc 210 en))
          e  (cdr (assoc 38 en))
          en (mapcar
               (function
                 (lambda (x)
                   (trans
                     (list (car x) (cadr x) e)
                     (trans '(0. 0. 1.) n 0)
                     0
                   ) ;_  trans
                 ) ;_  lambda
               ) ;_  function
               (mapcar
                 (function cdr)
                 (vl-remove-if-not
                   (function
                     (lambda (x1) (= (car x1) 10))
                   ) ;_  function
                   en
                 ) ;_  vl-remove-if-not
               ) ;_  mapcar
             ) ;_  mapcar
    ) ;_  progn
  ) ;_  if
) ;_  defun

viva

  • Guest
Re: LWPOLYLINE - how to capture
« Reply #9 on: August 28, 2006, 07:09:02 AM »
hi hangman,
         
Code: [Select]
(setq layinfo
(ssget "x" (list (cons 0 "lwpolyline") (cons 8 layername)))
  )
(setq enl (ssname layinfo no))

 (setq fis (vlax-curve-getstartpoint (vlax-ename->vla-object enl))) ---- starting point of pline
         (setq eis (vlax-curve-getendpoint (vlax-ename->vla-object enl)))  ------ ending point of pline

here enl indicates entity name.

regards
vivek


EDIT: Wrapped your code in [ code ] tags for ya
« Last Edit: August 28, 2006, 07:29:02 AM by nivuahc »

Hangman

  • Swamp Rat
  • Posts: 566
Re: LWPOLYLINE - how to capture
« Reply #10 on: August 29, 2006, 10:28:55 AM »
Well, thank you everyone for your advice & tips.  I really appreciate it.
I'm sorry to say, I'm a bit lost with the code MP and CAB have posted, but I can chew on it for a while.

Welcome Sepperl and thank you for your advice and comments.

Well, ...  I'd have to say I understand Vivek's code the best but I intend to try them all as I can learn from them so thanks again.

I have two routines I'm trying to fix.  One is a line join command.  I don't know who wrote it, but I'm trying to add the option of joining pline & line, pline & pline, or line & line automatically.  So the user will not have to know if the line(s) are pline or not, just simply pick the lines.

Code: [Select]
;Join.LSP:  Joins two broken colinear lines.
;
;__________________________________________________________________________

(defun c:join (/ a b ai va vb dst1 dst2 a1 b1 a2 b2 ent1 ent2
                 end1 end2 dst3 dst4 oldlst newlst)
  (defun mid (w z)
    (LIST (/ (+ (CAR w) (CAR z))2) (/ (+ (CADR w) (CADR z))2))
  )
  (setvar "cmdecho" 0)
  (setq a (cadr (entsel "\nSelect two lines to be joined: ")))
  (command ".select" a)
  (while (= a nil)
    (setq a (cadr (entsel "\nPlease Select two lines to be joined: ")))
    (command ".select" a)
  )
  (setq b (cadr (entsel)))
  (while (= b nil)
    (setq b (cadr (entsel)))
  )
  (command "")
  (setq ai (mid a b))
  (setq va (ssget a))
  (setq vb (ssget b))
  (setq a1 (cdr (assoc 10 (entget (setq ent1 (ssname va 0))))))
  (setq b1 (cdr (assoc 11 (entget (ssname va 0)))))
  (setq a2 (cdr (assoc 10 (entget (setq ent2 (ssname vb 0))))))
  (setq b2 (cdr (assoc 11 (entget (ssname vb 0)))))
  (setq dst1 (distance ai a1))
  (setq dst2 (distance ai b1))
  (if (< dst1 dst2)(setq end1 b1)(setq end1 a1))
  (setq dst3 (distance ai a2))
  (setq dst4 (distance ai b2))
  (if (< dst3 dst4)(setq end2 b2)(setq end2 a2))
  (setq oldlst (entget ent1))
  (setq newlst (subst (cons 10 end1)(assoc 10 oldlst) oldlst))
  (setq newlst (subst (cons 11 end2)(assoc 11 newlst) newlst))
  (entdel ent2)
  (entdel ent1)
  (entmake (cdr newlst))
  (princ)
)

So, I'm assuming I'd throw in Vivek's code to something like ...
alright, I've got to go play with this stuff, I'm not as efficient as you guys.  It takes me a while to get my two brain cells communicating to get something worked out.   :ugly:
I'll be back with a probable solution ... maybe.  :-D


Oh yeah, the other routine.
this routine is to fillet reinforcing.  The fillets are set, and I actually have the code so you can choose the line, if the line is a pline, it won't select, so you hit enter, then select the pline to fillet.
I need to add some filter in so the user can select either line or pline and it will automatically recognize the entity and run the routine.  Much like the line join command posted above.

Code: [Select]
(defun c:frt (/ defbar_size fillet_rad ssreinf ss1 ss2 ss3)
  (setvar "cmdecho" 1)
  (if (/= bar_size "")
    (setq defbar_size bar_size))
  (if (= defbar_size nil)
    (setq defbar_size 5.0))
;
  (setq bar_size (getreal (strcat "\nEnter Bar size <3 to 18> <#" (rtos defbar_size 2 0) ">: ")))
  (or bar_size (setq bar_size defbar_size))
  (progn
    (cond ( (= bar_size 3)
            (setq fillet_rad 1.125))
          ( (= bar_size 4)
            (setq fillet_rad 1.5))
          ( (= bar_size 5)
            (setq fillet_rad 1.875))
          ( (= bar_size 6)
            (setq fillet_rad 2.25))
          ( (= bar_size 7)
            (setq fillet_rad 2.625))
          ( (= bar_size 8)
            (setq fillet_rad 3.0))
          ( (= bar_size 9)
            (setq fillet_rad 4.75))
          ( (= bar_size 10)
            (setq fillet_rad 5.375))
          ( (and (>= bar_size 11)
                 (< bar_size 14))
            (setq fillet_rad 6.0))
          ( (and (>= bar_size 14)
                 (< bar_size 18))
            (setq fillet_rad 9.125))
          (T;(>= bar_size 18
            (setq fillet_rad 12.0))))
  (setvar "filletrad" fillet_rad)

  (setq ssreinf (ssget '((0 . "LINE"))))
  (if (/= ssreinf nil)
    (progn
      (setq ss1 (ssname ssreinf 0))
      (setq ss2 (ssname ssreinf 1))
      (command ".fillet" ss1 ss2)
      (setq ss3 (ssget "L"))
      (command ".pedit" ss1 "j" ss1 ss2 ss3 "" "x")))
  (if (= ssreinf nil)
    (command ".fillet" pause pause))

  (setvar "filletrad" 0.0) 
  (princ)
)


If you so choose to input some piece of code as to help these routines along, by all means, please do so.

Thanks.  :)
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~