Move Intersecting Points Away from line/pline

Move Intersecting Points Away from line/pline

cherrygate
Enthusiast Enthusiast
1,627 Views
20 Replies
Message 1 of 21

Move Intersecting Points Away from line/pline

cherrygate
Enthusiast
Enthusiast

I am doing bulk imports of various types of data and more often than not it is intersecting lines that I do not want them too. I would like to have some script that could bump them in the direction they are overlapping. I attached a screenshot example of "before and after" of what I currently manually do

 

cherrygate_0-1615993879428.png

 

Any help or guidance would be greatly appreciated, it takes me hours to go through and manually fix these data points

 

0 Likes
1,628 Views
20 Replies
Replies (20)
Message 2 of 21

ВeekeeCZ
Consultant
Consultant

RULE NUMBER ONE. ALWAYS POST A DRAWING - DWG!!

 

0 Likes
Message 3 of 21

cherrygate
Enthusiast
Enthusiast

@ВeekeeCZ I just uploaded it, see attached

0 Likes
Message 4 of 21

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

RULE NUMBER ONE. ALWAYS POST A DRAWING - DWG!!


 

“The second rule about posting a sample is you always post a drawing.” - TD

 

 

0 Likes
Message 5 of 21

john.uhden
Mentor
Mentor

Are you sure you're doing the right thing?  I'm a civil, and where the survey shots are taken is where they belong, not a foot or two away to accommodate some line work.  Maybe the linework is wrong.

Now, our shots are labeled, and we move the labels for legibility but not the shots themselves.  "X" marks the spot (to King Richard's tomb of course).

John F. Uhden

0 Likes
Message 6 of 21

Kent1Cooper
Consultant
Consultant

@cherrygate wrote:

.... I would like to have some script that could bump them in the direction they are overlapping. ....


A start on a routine is MovePerToObject.lsp with its MPO command, >here<.  It asks for a path object, selection of things to move, and distance to move them, and whether toward or away from the path.  There may be a common distance to move those that would suit your situation.  It could be modified easily enough to ask for a distance from the path object, but only if the things to be moved are all Blocks, or other unitary things like Circles, never assortments of separate pieces, because then their relationship to each other would usually shift.

Kent Cooper, AIA
Message 7 of 21

cherrygate
Enthusiast
Enthusiast

Thank you for the quick response. Yes, the objects being moved will ALWAYS be the same circle block I attached in the DWG and they will move away from the pline/line work. Is that something you could help me modifying that script to work like that? I do not know LISP well enough to know what to change to achieve that result.

 

In a perfect world, I would like to be able to selectsimilar all the circle blocks to move, and then run the command to move them away a set distance from the line. 

0 Likes
Message 8 of 21

pbejse
Mentor
Mentor

@cherrygate wrote:

...In a perfect world, I would like to be able to selectsimilar all the circle blocks to move, and then run the command to move them away a set distance from the line. 


Its easier to select the Polylines/Line than the blocks

Try this

 

(defun c:getawayfrome (/ i en pts blks n e ip ang)
  (if 
  (setq ssp (ssget '((0 . "LWPOLYLINE,LINE"))))
    (repeat (setq i (sslength ssp))
      (setq pts nil en	(ssname ssp (setq i (1- i))))
	  (if (eq (setq p (vlax-curve-getEndParam en)) (fix p))
	      (repeat (setq p (1+ (fix p)))
	        (setq pts (cons (vlax-curve-getPointAtParam en (setq p (1- p))) pts))
	      )
	      (setq pts (list (vlax-curve-getStartPoint en) (vlax-curve-getEndPoint en))
	    )
      )
      (if (setq blks (ssget "_F" pts '((0 . "INSERT")(2 . "Import"))))
	(repeat	(setq n (sslength blks))
	  (setq	e   (ssname blks (setq n (1- n)))
		ip  (cdr (assoc 10 (entget e)))
		ang (angle (setq fp (vlax-curve-getclosestpointto en ip))
			   ip
		    )
	  )
	  (Vlax-put (vlax-ename->vla-object e) 'InsertionPoint
		    (polar fp (if (eq ang 0.0)
				(+ (angle '(0.0 0.0 0.0)(vlax-curve-getfirstderiv  en
			   		(vlax-curve-getparamatpoint en
			     			fp)))
				  	(/ pi 2.)) ang)
			   20.00)
	  )
	)
      )
    )
  )
  (princ)
)

 

 

HTH

 

0 Likes
Message 9 of 21

Kent1Cooper
Consultant
Consultant

@cherrygate wrote:

.... Yes, the objects being moved will ALWAYS be the same circle block I attached in the DWG and they will move away from the pline/line work. ...


Try the attached MoveDistFromObject.lsp with its MDFO command.  Minimally tested in your drawing.

 

It will move anything you select, of any object type, to the specified distance [at its middle-of-bounding-box point] from the selected path object, whether that is away from it or toward it.  So you can get uniformity of distance even with things that don't intersect the path.  If you don't want things moved unless the path crosses them, you'll have to select only the ones that do, or something like @pbejse 's Fence-selection using the path for the Fence could be built in [though that will have trouble if the path is a Polyline that includes arc segments].

Kent Cooper, AIA
0 Likes
Message 10 of 21

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

... or something like @pbejse 's Fence-selection using the path for the Fence could be built in [though that will have trouble if the path is a Polyline that includes arc segments].


You got a point there

 

(Defun c:Imoutofhere ( / blks n e ip abg fp )
(if (setq blks (ssget "_:L" '((0 . "INSERT")(2 . "Import"))))
  (repeat (setq n (sslength blks))
	   (setq e  (ssname blks (setq n (1- n)))
		 ip (cdr (assoc 10 (entget e))))
	   (if (setq ss	(ssget "C"
			       (polar ip (* pi 0.25) (* 12.5 (sqrt 2)))
			       (polar ip (* pi 1.25) (* 12.5 (sqrt 2)))
			       '((0 . "LWPOLYLINE,LINE,ARC"))
			)
	       )
	     (progn
	       (setq ang (angle	(setq fp (vlax-curve-getclosestpointto
					   (setq en (ssname ss 0))
					   ip
					 )
				)
				ip
			 )
	       )
	       (Vlax-put (vlax-ename->vla-object e)
		 'InsertionPoint(polar	fp
				(if (eq ang 0.0)
				  (+ (angle '(0.0 0.0 0.0)
					    (vlax-curve-getfirstderiv
					      en
					      (vlax-curve-getparamatpoint
						en
						fp
					      )
					    )
				     )
				     (/ pi 2.)
				  )
				  ang
				)
			20.00
		 )
		 
	       )
	     )
	   )
	 )
  )
(princ)
  )

 

 

0 Likes
Message 11 of 21

Kent1Cooper
Consultant
Consultant

@pbejse wrote:....
...
	   (if (setq ss	(ssget "C"
			       (polar ip (* pi 0.25) (* 12.5 (sqrt 2)))
			       (polar ip (* pi 1.25) (* 12.5 (sqrt 2)))
			       '((0 . "LWPOLYLINE,LINE,ARC"))
....

That isn't foolproof, either.  It would move a Block like this that doesn't cross the path [the red is the Crossing window made by the code above]:

Kent1Cooper_0-1616004215301.png

 

Kent Cooper, AIA
0 Likes
Message 12 of 21

ronjonp
Mentor
Mentor

@Kent1Cooper wrote:

@pbejse wrote:....

 

...
	   (if (setq ss	(ssget "C"
			       (polar ip (* pi 0.25) (* 12.5 (sqrt 2)))
			       (polar ip (* pi 1.25) (* 12.5 (sqrt 2)))
			       '((0 . "LWPOLYLINE,LINE,ARC"))
....

 


That isn't foolproof, either.  It would move a Block like this that doesn't cross the path [the red is the Crossing window made by the code above]:

Kent1Cooper_0-1616004215301.png

 


@Kent1Cooper  This scenario is true, but there is also something nice about consistency 😎.. also should there be a check if the moved block is being placed on another object?

ronjonp_0-1616005705856.png

 

0 Likes
Message 13 of 21

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

@pbejse wrote:....

That isn't foolproof, either.  It would move a Block like this that doesn't cross the path [the red is the Crossing window made by the code above]:

 


I admit i did not actually read that part of the message until now😆

-- If you don't want things moved unless the path crosses them--  

 

I do have an idea to get past that issue.... let me see if i can quickly add something to the second code.

 

@ronjonp  Yeah, there's that  🙂

 

Perhaps we should wait for the OP to respond, before doing anything else

 

 

0 Likes
Message 14 of 21

Kent1Cooper
Consultant
Consultant

@pbejse wrote:
.... I do have an idea to get past that issue....

I can imagine what that would be, at least with a circular Block -- if it finds a path with the crossing window, check the actual current distance from the path, and move only if that distance is small enough that they must overlap.

 

Of course, that's all very narrow-focus, based on only Blocks, and only those of a specific Block name and at a specific size and shape [and that may suit the OP just fine].

Kent Cooper, AIA
0 Likes
Message 15 of 21

CodeDing
Advisor
Advisor

 

Based on this:


@cherrygate wrote:

Yes, the objects being moved will ALWAYS be the same circle block I attached in the DWG and they will move away from the pline/line work


Here's my take. You can update the "getAwayDist" variable to any number you'd like.

(defun c:GETAWAY ( / ssBlocks ssLwork getAwayDist cnt lwList blk eg pBase pTemp pClose minDist tmpDist)
  (vl-load-com)
  (if (and (setq ssBlocks (ssget '((0 . "INSERT") (2 . "Import"))))
           (setq ssLwork (ssget '((0 . "LWPOLYLINE,LINE,ARC"))))
      );and
    (progn
      (setq getAwayDist 25)
      ;; Get linework entity names for later
      (repeat (setq cnt (sslength ssLwork))
        (setq lwList (cons (ssname ssLwork (setq cnt (1- cnt))) lwList))
      );repeat
      ;; For each blk, determine closest line, then move to 'getAwayDist'
      (repeat (setq cnt (sslength ssBlocks))
        (setq blk (ssname ssBlocks (setq cnt (1- cnt))))
        (setq eg (entget blk))
        (setq pBase (cdr (assoc 10 eg)))
        (setq minDist nil)
        ;; Determine closest line point
        (foreach lw lwList
          (setq pTemp (vlax-curve-getclosestpointto lw pBase))
          (setq tmpDist (distance pBase pTemp))
          (if (or (not minDist)
                  (< tmpDist minDist)
              );or
            (setq minDist tmpDist pClose pTemp)
          );if
        );foreach
        ;; Move to 'getAwayDist'
        (vla-move
          (vlax-ename->vla-object blk)
          (apply 'vlax-3d-point pBase)
          (apply 'vlax-3d-point (polar pClose (angle pClose pBase) getAwayDist))
        );vla-move
      );repeat
      (prompt "\nGETAWAY Complete.")
    );progn
  ;else
    (prompt "\nOne or Both selection sets were bad.")
  );if
  (princ)
);defun

 

-- EDIT --

Some Notes:

- This will always move the block to the "getAwayDist".. so even blocks further away will be moved closer.

- This does not account for other intersecting/near linework (as discussed by others previously).

 

Best,

~DD

0 Likes
Message 16 of 21

ronjonp
Mentor
Mentor

Based on the sample drawing, this is how I would approach it:

 

(defun c:foo (/ bl d lw o p p2 s)
  ;; RJP » 2021-03-18
  (cond
    ((setq s (ssget "_X"
		    '((-4 . "<OR")
		      (0 . "LWPOLYLINE")
		      (-4 . "<AND")
		      (0 . "INSERT")
		      (2 . "IMPORT")
		      (-4 . "AND>")
		      (-4 . "OR>")
		     )
	     )
     )
     (foreach e	(mapcar 'cadr (ssnamex s))
       (if (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'insertionpoint)
	 (setq bl (cons o bl))
	 (setq lw (cons o lw))
       )
     )
     (foreach b	bl
       (setq p (vlax-get b 'insertionpoint))
       (setq d (* 2. (vla-get-xscalefactor b)))
       (if
	 (vl-some
	   '(lambda (x)
	      (and (vlax-invoke b 'intersectwith x 0) (setq p2 (vlax-curve-getclosestpointto x p)))
	    )
	   lw
	 )
	  (vlax-invoke b 'move p (polar p (angle p2 p) (- d (distance p p2))))
       )
     )
    )
  )
  (princ)
)

2021-03-18_6-12-39.gif

 

 

 

Message 17 of 21

Anonymous
Not applicable

If your moving the line you can use the offset command and in the command line you can set it to how ever many feet, etc. you want up, down, left or right.. If your trying to move the numbers - circles away from your line then use the move command.

0 Likes
Message 18 of 21

Anonymous
Not applicable

Or use the move button on the ribbon or the command line. doesn't matter.

0 Likes
Message 19 of 21

CodeDing
Advisor
Advisor

@Anonymous 


@Anonymous wrote:

If your trying to move the numbers - circles away from your line then use the move command.


Assuming that's OP's current method, they state in their original post that it currently takes hours to complete. An automated approach, instead of individual Select/Move commands, seems reasonable here.

 

Best,

~DD

0 Likes
Message 20 of 21

ВeekeeCZ
Consultant
Consultant

@ronjonp wrote:

2021-03-18_6-12-39.gif

 

 


This is confusing to me. I wonder whether Before is really Before and After is really After. It somehow seems that at some moment is After Before while Before is really Before and then there is no After. In other moment is Before After while After is really After and now where is Before gone? Also, those moments comes back and forth... so they could be the other way around. Really confusing.

0 Likes