Author Topic: Extend Mlines  (Read 1920 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Extend Mlines
« on: February 02, 2007, 01:50:49 PM »
Ok,

So i have a drawing with about 500 two point mlines in it. What I need to do is extend each end 3 feet but I'm unsure how to go about doing this.


My pseudo code is:
1. Gather mlines. <--can do
2. Get endpoints and determine angle.<-can do
3. Calculate point 3 feet further on same plane of angle <-- not sure how to do
4. Entmod <-- not sure about this one either

Any help would be appreciated.

Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Extend Mlines
« Reply #1 on: February 02, 2007, 02:18:16 PM »
You can get the points of the mline with all the number 11 dxf codes, or you can use the 'coordinates' property.  If they are only two points, then you can just get the angle one way, then get the oppsite.  Use polar to make the new points, then just update the coordinates list, update the object, and all is good.

Code: [Select]
Command: (setq coordlist (vlax-get ob2 'coordinates))
 (9.13228 16.745 0.0 27.6326 16.745 0.0)

Command: (setq ang (angle (list (car coordlist) (cadr coordlist) (caddr coordlist)) (cdddr coordlist)))
 0.0

(setq stpt (list (car coordlist) (cadr coordlist) (caddr coordlist)))
 (9.13228 16.745 0.0)

Command: (setq endpt (cdddr coordlist))
 (27.6326 16.745 0.0)

Command: (setq stpt2 (polar stpt pi 3))
(6.13228 16.745 0.0)

Command: (setq endpt2 (polar endpt 0.0 3))
(30.6326 16.745 0.0)

Command: (setq newcoordlist (append stpt2 endpt2))
(6.13228 16.745 0.0 30.6326 16.745 0.0)

Command: (vlax-put ob2 'coordinates newcoordlist)
nil

Command: (vla-update ob2)
nil

 :-D That is one bad real quick example.
Tim

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

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Extend Mlines
« Reply #2 on: February 02, 2007, 02:41:21 PM »
Thanks Tim.....I'll give it a whirl :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Extend Mlines
« Reply #3 on: February 02, 2007, 02:42:42 PM »
Thanks Tim.....I'll give it a whirl :)
You're welcome.
Tim

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

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Extend Mlines
« Reply #4 on: February 02, 2007, 04:56:14 PM »
I got it working...thanks for your help Tim.

Code: [Select]
(defun c:x (/ ss num index obj lst stpt endpt ang ang2 stpt2 endpt2)
  (setq num   (getreal "\n Enter length to extend sleeve: ")
ss    (ssget '((0 . "MLINE")))
index -1
  )
  (while (< (setq index (1+ index)) (sslength ss))
    (setq obj (vlax-ename->vla-object (ssname ss index))
  lst (vlax-get obj 'coordinates)
  stpt (list (car lst) (cadr lst) (caddr lst))
  endpt (cdddr lst)
  ang (angle stpt endpt)
  ang2 (angle endpt stpt)
  stpt2 (polar stpt ang2 num)
  endpt2 (polar endpt ang num)
  lst (append stpt2 endpt2)
    )
    (vlax-put obj 'coordinates lst)
    (vla-update obj)
  )
)

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC