Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with a Lisp. Jumping Crossing Lines.

5 REPLIES 5
Reply
Message 1 of 6
bartonrj25
1372 Views, 5 Replies

Need help with a Lisp. Jumping Crossing Lines.

Attached is a code that is close to what I need but I need to know if there is a way to to make this code work on polylines too? Also, turn the lines with the "jumps" into a single line entity like a polyline join? I would be interested if anyone knows of a lisp like that or could manipulate this code. Thank you.

 

 

(defun C:jmp(/ *error* ang ans bp1 bp2 elist1 elist2 entlist1 entlist2 gap ip osm nom pe1 pe2 ps1 ps2 sellist sset1 sset2 vflag)
  (vl-load-com)
 (defun *error* (msg)
      (vla-endundomark (vla-get-activedocument
              (vlax-get-acad-object))
	      )
    (cond ((or (not msg)
	       (member msg '("console break" "Function cancelled" "quit / exit abort"))
	       )
	   )
	  ((princ (strcat "\nError: " msg)))
	  )
    (setvar "cmdecho" 1)
    (if	osm
      (setvar "osmode" osm)
    )
    (if	nom
      (setvar "osmode" nom)
    )
    (princ)
    )
  (vla-startundomark (vla-get-activedocument
              (vlax-get-acad-object))
	      )
  (setq osm(getvar "OSMODE"))
  (setvar "OSMODE" 0)
  (princ "\nZoom objects to be visible on screen: ")
(command "_.zoom" "w" pause pause)	 
(setvar "nomutt" 0)
(setq nom (getvar "nomutt"))
	 
(setvar "nomutt" 0)
(princ "\nSelect vertical lines: ")
(setvar "nomutt" 1)
(setq sset1 (ssget ":L" '((0 . "line"))))
(setvar "nomutt" 0)
(princ "\nSelect horizontal lines: ")
(setvar "nomutt" 1)
(setq sset2 (ssget ":L" '((0 . "line"))))
(setvar "nomutt" 0)
(setq *gap* 4);<-- set your gap between lines here
(setq gap (getreal (strcat "\nEnter a gap <" (rtos *gap*) ">: ")))
(cond ((not gap)(setq gap *gap*)))
(setq entlist1 (vl-remove-if 'listp(mapcar 'cadr (ssnamex sset1)))
      entlist2 (vl-remove-if 'listp(mapcar 'cadr (ssnamex sset2))))
 (initget 1 "Vertical Horizontal" )
 (setq ans (getkword "\nChoose lines to be jumped over [Vertical/Horizontal] <H>:"))
(if (eq ans "Vertical")(setq vflag t)(setq vflag nil))
(if vflag (progn
	    ;;swap references to selected objects :
	    (setq sellist (list entlist1 entlist2)
		  entlist2(car sellist)
		  entlist1(cadr sellist))
		
	    (setq ang (/ pi 2))
	    )
  (setq ang 0)
  )
(foreach ent1 entlist1
  (setq elist1 (entget ent1))
  (setq ps1 (cdr (assoc 10 elist1)))
   (setq pe1 (cdr (assoc 11 elist1)))
  (foreach ent2 entlist2
     (setq elist2 (entget ent2))
  (setq ps2 (cdr (assoc 10 elist2)))
    (setq pe2 (cdr (assoc 11 elist2)))
    (setq ip (inters  ps2 pe2 ps1 pe1 nil))
    (setq ip (vlax-curve-getclosestpointto ent1 ip))
    (setq bp1 (polar ip ang (/ gap 2)))
    (setq bp2 (polar ip (+ ang pi) (/ gap 2)))
    
    (command "_.break" bp1 bp2)

      (command "_.arc" bp1 "_E" bp2 "_A" 180.)

    )
)
  (command "_.zoom" "p")
(*error* nil)
  (princ)
  )
(prompt "\n   >>>   Type JMP to execute...")
(prin1)

 

5 REPLIES 5
Message 2 of 6
bartonrj25
in reply to: bartonrj25

(defun C:jmp(/ *error* ang bp1 bp2 elist1 elist2 entlist1 entlist2 gap ip osm nom pe1 pe2 ps1 ps2 sset1 sset2)
(vl-load-com)
(defun *error* (msg)
(vla-endundomark (vla-get-activedocument
(vlax-get-acad-object))
)
(cond ((or (not msg)
(member msg '("console break" "Function cancelled" "quit / exit abort"))
)
)
((princ (strcat "\nError: " msg)))
)
(setvar "cmdecho" 1)
(if osm
(setvar "osmode" osm)
)
(if nom
(setvar "osmode" nom)
)
(princ)
)
(vla-startundomark (vla-get-activedocument
(vlax-get-acad-object))
)
(setq osm(getvar "OSMODE"))
(setvar "OSMODE" 0)
(princ "\nZoom objects to be visible on screen: ")
(command "_.zoom" "w" pause pause)
(setvar "nomutt" 0)
(setq nom (getvar "nomutt"))

(setvar "nomutt" 0)
(princ "\nSelect vertical lines: ")
(setvar "nomutt" 1)
(setq sset1 (ssget ":L" '((0 . "line"))))
(setvar "nomutt" 0)
(princ "\nSelect horizontal lines: ")
(setvar "nomutt" 1)
(setq sset2 (ssget ":L" '((0 . "line"))))
(setvar "nomutt" 0)
(setq *gap* 4);<-- set your gap between lines here
(setq gap (getreal (strcat "\nEnter a gap <" (rtos *gap*) ">: ")))
(cond ((not gap)(setq gap *gap*)))
(setq entlist1 (vl-remove-if 'listp(mapcar 'cadr (ssnamex sset1)))
entlist2 (vl-remove-if 'listp(mapcar 'cadr (ssnamex sset2))))

(foreach ent1 entlist1
(setq elist1 (entget ent1))
(setq ps1 (cdr (assoc 10 elist1)))
(setq pe1 (cdr (assoc 11 elist1)))
(foreach ent2 entlist2
(setq elist2 (entget ent2))
(setq ps2 (cdr (assoc 10 elist2)))
(setq pe2 (cdr (assoc 11 elist2)))
(setq ip (inters ps2 pe2 ps1 pe1 nil))
(setq ip (vlax-curve-getclosestpointto ent1 ip))
(setq bp1 (polar ip 0 (/ gap 2)))
(setq bp2 (polar ip pi (/ gap 2)))

(command "_.break" bp1 bp2)

(command "_.arc" bp1 "_E" bp2 "_A" 180.)

)
)
(command "_.zoom" "p")
(*error* nil)
(princ)
)
(prompt "\n >>> Type JMP to execute...")
(prin1)

Message 3 of 6
Kent1Cooper
in reply to: bartonrj25

Just to save us the trouble of plowing through to compare:  Is that second post the same code as in the first, just not contained in a Code Window, or is it different?

 

One complication of including Polylines [and/or also Circles, Arcs, Splines, Ellipses, etc.] is that any one selected object may intersect not only more than one other object, but possibly even a single other object in more than one place.  That makes simply stepping through lists of entities problematic, since sometimes you'll want a jump across a new object that wasn't in the original selection but was the result of Breaking one earlier in the list.

 

But there are routines out there that may have worked out such complications.  There are lots to break all selected objects at all intersections, with various differences in approach and options and limitations [such as on entity type(s)].  If you put something like "break all intersections" in the Search window on this site you'll find a bunch of things, or look here, or at this one which lets you specify the gap size,  Maybe you can start with one of those that most closely does what you want, including more entity types than just Lines, and the drawing of the Arcs across the gaps can be worked into it.  [Maybe some of the ones you'll find with a Search already do the Arcs -- perhaps what you posted comes from here?]

Kent Cooper, AIA
Message 4 of 6
bartonrj25
in reply to: Kent1Cooper

The second code is the same.

 

This routine does go through the trouble of breaking all of the intersections, gives me a gap size option and draws the arc over the appropriate gap. My problem is that this routine only works with standard lines. I would find it alot more useful if it could be used with polylines and to go another step, to be able to join the lines into a single polyline after the arc has been created. Simular to a multiple polyline edit using the join option.

 

I could aways just join the lines myself in a second command after running the routine. I just thought it would be nice to kill two birds with one stone if at all possible.

 

 

Message 5 of 6
Kent1Cooper
in reply to: bartonrj25


@bartonrj25 wrote:

.... 

This routine does go through the trouble of breaking all of the intersections, gives me a gap size option and draws the arc over the appropriate gap. My problem is that this routine only works with standard lines. I would find it alot more useful if it could be used with polylines and to go another step, to be able to join the lines into a single polyline after the arc has been created. ....


Would these always be of only horizontal and vertical segments, and would you always want the horizontal one of an intersecting pair broken/jumped as your current routine does?  It seems doable, but it won't be as simple as just also allowing selection of Polylines [unless they are always of only one line segment, which doesn't seem likely].  Assuming they would sometimes bend, it would need to include a mechanism [there's an ....intersectwith... function] to find possible multiple intersections between two objects.

 

Joining the arcs and the broken objects into Polylines actually would be an advantage, because without doing that, you would sometimes have new objects you want broken, that weren't in the original selection, as I described before.  But it would need to be done carefully, maintaining the entity name of the original Polyline.  Fortunately, unlike with some other entity types, when you Break a LWPolyline, the "upstream" portion of it retains the original entity name, so Pedit-ing with the Join option should work.

 

I would assume it would also be preferable to have it remember the gap/jump size you last asked for, instead of always offering only 4 as the default.

Kent Cooper, AIA
Message 6 of 6
bartonrj25
in reply to: Kent1Cooper

Yes, these will only apply to vertical and horizontal segments (wiring schematics). It would be nice to have the choice of choosing vertical or horizontal breaking/arc segment on the intersecting pair but I could live with just horizontal. Yes, it would be preferable to remember the previous gap/jump size. From your decription and suggestions, it sounds like you know exactly what I am looking for.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost