Jump to content

Distribute closed polylines


Juergen

Recommended Posts

This will space things left to right as long as they are all in the positive x and y cords

Select one row at a time.

 

;;----------------------------------------------------------------------------;;
;; Move Poly to line and in order
(defun C:MP (/ SS poly obj LL UR L&W lst BP x ) 
  (vl-load-com)
  (if (setq SS (ssget))
    (progn
      (foreach poly (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
        (vla-getboundingbox (setq obj (vlax-ename->vla-object poly)) 'minpt 'maxpt)
        (setq LL (vlax-safearray->list minpt)
              UR (vlax-safearray->list maxpt)
              L&W (mapcar '- UR LL)
        )
        (setq lst (cons (list obj LL (car L&W)) lst))
      )
      (setq lst (vl-sort lst '(lambda (a b) (< (distance '(0 0 0) (cadr a)) (distance '(0 0 0) (cadr b)))))) ;sorts left to right
      (setq BP (cadr (car lst))) 
      ;(setq BP (getpoint "\nPick Point")) ;use if you want to pick a spot
      (setq dist (getdist "\nSpacing: "))
      (foreach ent lst
        (vla-move (car ent) (cadr ent) BP)
        (setq BP (polar BP 0 (+ (caddr ent) dist)))
      )
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

Hi mhupp,

 

thanks for the program.

 

I get the following message:

error: no conversion of the lisp value to VARIANT with the following type: (0.0 0.0 0.0)

 

  • I select the objects
  • Pick Point: I click a point in the drawing
  • Spacing: I write e.g. 1000
Link to comment
Share on other sites

Every thing is working on this end

If your picking a point and spacing sounds like the error is with the vla-move

Using (command for move instead

;;----------------------------------------------------------------------------;;
;; Move Poly to line and in order
(defun C:MP (/ SS poly obj LL UR L&W lst BP x ) 
  (vl-load-com)
  (if (setq SS (ssget))
    (progn
      (foreach poly (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
        (vla-getboundingbox (vlax-ename->vla-object poly) 'minpt 'maxpt)
        (setq LL (vlax-safearray->list minpt)
              UR (vlax-safearray->list maxpt)
              L&W (mapcar '- UR LL)
        )
        (setq lst (cons (list poly LL (car L&W)) lst))
      )
      (setq lst (vl-sort lst '(lambda (a b) (< (distance '(0 0 0) (cadr a)) (distance '(0 0 0) (cadr b)))))) ;sorts left to right
      ;(setq BP (cadr (car lst))) 
      (setq BP (getpoint "\nPick Point: ")) ;use if you want to pick a spot
      (setq dist (getdist "\nSpacing: "))
      (foreach ent lst
        ;(vla-move (car ent) (cadr ent) BP) ;error maybe?
        (command "_.Move" (car ent) "" "_non" (cadr ent) "_non" BP)
        (setq BP (polar BP 0 (+ (caddr ent) dist)))
      )
    )
  )
  (princ)
)

 

 

Link to comment
Share on other sites

  • 2 months later...

Yes

 

Needs more code as needs two steps select plines and work out spacing order, as per Mhupp code,  then reslect pline and select what is inside it, then move.

 

Like everyone need some time Mhupp may answer sooner.

Link to comment
Share on other sites

36 minutes ago, Juergen said:

The circles etc should be moved with the polylines.

It should all be together.

Why are you doing this? And .. if you really need to do this why is it not more organized as blocks ?

Link to comment
Share on other sites

I get the drawing sent to me like this, everything is coherent here.

It's easier for me to edit when everything is distributed.

If I have to select everything individually, I can move the selection right away.

Is there a way that I select everything and a block is created for each closed polyline?

Link to comment
Share on other sites

7 hours ago, Juergen said:

I get the drawing sent to me like this, everything is coherent here.

It's easier for me to edit when everything is distributed.

If I have to select everything individually, I can move the selection right away.

Is there a way that I select everything and a block is created for each closed polyline?

You can do a ZOOM Object, and scale to 0.9X for each poly , then edit as need 

image.thumb.png.b83aaf500eccc09c62cf7ac9c94c239b.png

 

Link to comment
Share on other sites

Devitg is on right path, for simplicity I would use a SSGET "F" option so pline order is recorded saves all the sorting of X & y etc. I would also copy rather than move helps if things go wrong. Note not sure why but my Bricscad does the ssget F backwards.

; very simple copy plines and whats inside to right
; By AlanH March 2023
(defun c:wow2 ( / pt1 pt2 ss ss2 x dist oldsnap)
(setq dist (getdist "\nEnter distance X "))
(setq dist2 (- (getdist "\nEnter distance y ")))
(setq d2 dist y 0.0)
(while (setq pt1 (getpoint "\nPick 1st point Enter to exit "))
(setq pt2 (getpoint pt1 "\nPick point 2 "))
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq x 0)
(setq ss (ssget "F" (list pt1 pt2)  '((0 . "LWPOLYLINE"))))
(if (= ss nil)
(alert "No objects found")
(repeat (sslength ss)
(setq plent (ssname ss x))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
(setq co-ord (cons (last co-ord) co-ord)) ; make a closed list
(setq ss2 (ssget "wP" co-ord))
(if (= ss2 nil) (setq ss2 (ssadd)))
(setq ss2 (ssadd plent ss2))
(setq x (1+ x) d2 (* x d2))
(command "copy" ss2 "" "0,0" (list d2 Y))
(setq ss2 nil)
)
)
(setq d2 dist)
(setq y (+ Y dist2))
)
(setvar 'osmode oldsnap)
(princ)
)
(c:wow2)

For repeated use can put the get pt1 inside a while so pick more. I used pick left to right. 

 

Probably needs a bit more enhancing.

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

Hi Bigal,

i tried to use your lisp.

I mark everything and click the 1st point then the 2nd point

but I get the message no objects found.

What am I doing wrong?

Link to comment
Share on other sites

Checked again code is working the outlines must be individual plines, if they are lines will not work.

 

Your words for each closed polyline

 

image.thumb.png.577fc704d0fb0f124615388607b57fc2.png

Link to comment
Share on other sites

I get following info from the command line:

Pick 1st point Pick point 2 Application ERROR: SSGET W/C requires two points

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...