Simple line break and jump AutoLISP

Simple line break and jump AutoLISP

andrew_k
Enthusiast Enthusiast
15,342 Views
37 Replies
Message 1 of 38

Simple line break and jump AutoLISP

andrew_k
Enthusiast
Enthusiast

Hi all,

I created a simple AutoLISP command to speed up creating line breaks and jumps for use in a wiring diagram. The command breaks the selected line and draws an arc to show that the lines do not cross / connect.

0 Likes
Accepted solutions (4)
15,343 Views
37 Replies
Replies (37)
Message 21 of 38

Kent1Cooper
Consultant
Consultant
Accepted solution

@andrew_k wrote:

.... It has trouble with standard lines .... "error: bad argument value: AcDbCurve 57" ....


That's what I get for not testing it.  I'm sure it's because after converting to a Polyline, its entity name is different, so it needs to reset the variable.  Try this:

(defun c:LineJump (/ a d e i o p p1 p2 p3)  ;; Adds a 'hop' to a LWPolyline or Line
  (setq a (getdist "\nSpecify arc length: "))
  (setvar 'peditaccept 1); [could save current value and reset later if desired]
  (while
    (and
      (setq e (entsel "\nPick a line or polyline to add a hop: "))
      (wcmatch (setq etype (cdr (assoc 0 (entget (car e))))) "LINE,LWPOLYLINE")
    ); and
    (if (= etype "LINE")
      (progn ; then
        (command "_.pedit" (car e) ""); convert Line to Polyline
        (setq e (entlast)); <-- new entity name in variable
      ); progn
    ); if
    (setq p (getpoint "\nSpecify intersection: "))
    (setq i (1+ (fix (vlax-curve-getparamatpoint e p)))); [not resetting e here]
    (setq d (vlax-curve-getdistatpoint e p))
    (setq p1 (vlax-curve-getpointatdist e (+ d a)))
    (setq p2 (vlax-curve-getpointatdist e (- d a)))
    (setq o (vlax-ename->vla-object e)); make into VLA object for next functions:
    (vlax-invoke o 'addvertex i (mapcar '+ p1 '(0 0)))
    (vlax-invoke o 'addvertex i (mapcar '+ p2 '(0 0)))
    (vla-setbulge ; make into half-circle arc segment
      o
      i
      (cond
        ((< (angle '(0 0) p1) (angle '(0 0) p2)) -1.)
        (1.)
      ); cond
    ); vla-setbulge
  ); while
  (princ)
)
(vl-load-com)
Kent Cooper, AIA
0 Likes
Message 22 of 38

andrew_k
Enthusiast
Enthusiast

This is better than I could have hoped for! Thanks a lot!

0 Likes
Message 23 of 38

andrew_k
Enthusiast
Enthusiast

I am getting a new error now -

error: unable to get ObjectID: (<Entity name: 1734bd6b820> (718.945 2383.31 0.0))

Any ideas?

0 Likes
Message 24 of 38

Kent1Cooper
Consultant
Consultant

@andrew_k wrote:

I am getting a new error now -

error: unable to get ObjectID: (<Entity name: 1734bd6b820> (718.945 2383.31 0.0))

Any ideas?


Looking more closely, I assume that's when you're doing it with a Polyline, because I changed the setting of the 'e' variable to be just the entity name [instead of the result from (entsel)] inside the Line-conversion part.  Try adding an 'else' argument to that (if) function:

 

    (if (= etype "LINE")
      (progn ; then
        (command "_.pedit" (car e) ""); convert Line to Polyline
        (setq e (entlast)); <-- new entity name in variable
      ); progn
      (setq e (car e)); else -- Polyline entity name instead of that + pick point
    ); if

 

Kent Cooper, AIA
Message 25 of 38

andrew_k
Enthusiast
Enthusiast
Awesome, it works now! Thank you once again Kent!
0 Likes
Message 26 of 38

JarleVelle1442
Explorer
Explorer

Is it possible to make it remember the arc length, so we dont have to type it each time?

 

jarle

0 Likes
Message 27 of 38

Kent1Cooper
Consultant
Consultant

@JarleVelle1442 wrote:

Is it possible to make it remember the arc length, so we dont have to type it each time?


If in my code in Message 21, replace this much at the top:

 

(defun c:LineJump (/ a d e i o p p1 p2 p3)  ;; Adds a 'hop' to a LWPolyline or Line
  (setq a (getdist "\nSpecify arc length: "))

 

with this:

 

(defun c:LineJump (/ d e i o p p1 p2 p3)  ;; Adds a 'hop' to a LWPolyline or Line
  (initget (if *LJArc* 6 7)); no 0, no negative, no Enter on first use
  (setq *LJArc*
    (cond
      ( (getdist
          (strcat
            "\nSpecify arc length"
            (if *LJArc* (strcat " <" (rtos *LJArc*) ">") ""); offer default if present
            ": "
          ); strcat
        ); getdist
      ); User-input condition
      (*LJArc*); prior value on Enter when permitted
    ); cond
  ); setq

 

AND replace the later occurrences of the 'a' variable with *LJArc*:

 

    (setq p1 (vlax-curve-getpointatdist e (+ d *LJArc*)))
    (setq p2 (vlax-curve-getpointatdist e (- d *LJArc*)))

 

NOTE the removal of 'a' from the localized variables list.  *LJArc* becomes a global variable that will remain after the routine is finished, with a name that is not likely to be overwritten by any other routine, as 'a' might be.

Kent Cooper, AIA
0 Likes
Message 28 of 38

JarleVelle1442
Explorer
Explorer

If you make a jump on a line, it turns into a polyline and then it wont work for the next jump point on the same line.

 

regards

 

0 Likes
Message 29 of 38

Kent1Cooper
Consultant
Consultant

@JarleVelle1442 wrote:

If you make a jump on a line, it turns into a polyline and then it wont work for the next jump point on the same line.


You need to incorporate the correction in Message 24.

Kent Cooper, AIA
Message 30 of 38

Kent1Cooper
Consultant
Consultant
Accepted solution

@JarleVelle1442 wrote:

Is it possible to make it remember the arc length, so we dont have to type it each time?


Here's the whole thing with that as well as the correction in Message 24 incorporated:

(defun c:LineJump (/ d e i o p p1 p2 p3)  ;; Adds a 'hop' to a LWPolyline or Line
  (initget (if *LJArc* 6 7)); no 0, no negative, no Enter on first use
  (setq *LJArc*
    (cond
      ( (getdist
          (strcat
            "\nSpecify arc length"
            (if *LJArc* (strcat " <" (rtos *LJArc*) ">") ""); offer default if present
            ": "
          ); strcat
        ); getdist
      ); User-input condition
      (*LJArc*); prior value on Enter when permitted
    ); cond
  ); setq
  (setvar 'peditaccept 1); [could save current value and reset later if desired]
  (while
    (and
      (setq e (entsel "\nPick a line or polyline to add a hop: "))
      (wcmatch (setq etype (cdr (assoc 0 (entget (car e))))) "LINE,LWPOLYLINE")
    ); and
    (if (= etype "LINE")
      (progn ; then
        (command "_.pedit" (car e) ""); convert Line to Polyline
        (setq e (entlast)); <-- new entity name in variable
      ); progn
      (setq e (car e)); else -- Polyline entity name instead of that + pick point
    ); if
    (setq p (getpoint "\nSpecify intersection: "))
    (setq i (1+ (fix (vlax-curve-getparamatpoint e p)))); [not resetting e here]
    (setq d (vlax-curve-getdistatpoint e p))
    (setq p1 (vlax-curve-getpointatdist e (+ d *LJArc*)))
    (setq p2 (vlax-curve-getpointatdist e (- d *LJArc*)))
    (setq o (vlax-ename->vla-object e)); make into VLA object for next functions:
    (vlax-invoke o 'addvertex i (mapcar '+ p1 '(0 0)))
    (vlax-invoke o 'addvertex i (mapcar '+ p2 '(0 0)))
    (vla-setbulge ; make into half-circle arc segment
      o
      i
      (cond
        ((< (angle '(0 0) p1) (angle '(0 0) p2)) -1.)
        (1.)
      ); cond
    ); vla-setbulge
  ); while
  (princ)
)
(vl-load-com)
Kent Cooper, AIA
Message 31 of 38

Sea-Haven
Mentor
Mentor

An alternative way of keeping radius. Kent please feel free to use. Note Multi getvals.lsp must be in a support path or use full path to load.

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(if (= *LJArc* nil)(setq *LJArc* 5)) ; change to suit initial value
(setq *LJArc* (atof  (car (AH:getvalsm (list "Enter value " "Radius " 5 4 (rtos *LJArc* 2 0))))))

 

SeaHaven_0-1653453961304.png

 

0 Likes
Message 32 of 38

Hieu.Nguyen_Aurecon
Explorer
Explorer
The Lisp worked quite well, thanks. But can you make it work in any UCS ? Every time i use it, i need to set UCS to "World system".
0 Likes
Message 33 of 38

Sea-Haven
Mentor
Mentor

Are you using some code that resets the UCS ? Normally it would be "World" so I would look for that 1st, adding reset to world is easy but should not be necessary.

0 Likes
Message 34 of 38

nbonnett-murphy
Advocate
Advocate

When I use this on a horizontal line, it puts the bulge on the bottom of the polyline. Does anyone know how to flip it? (without mirroring manually obviously)

 

I assume it has to do with (< (angle '(0 0) p1) (angle '(0 0) p2)) -1.) on line 41, but I don't know lisp syntax enough to figure it out.

0 Likes
Message 35 of 38

nbonnett-murphy
Advocate
Advocate

Disregard, it's referencing the x-axis, and someone had drawn what I was working on below 0,0.

 

I'd still like to understand how that angle function is working though. the -1. is confusing me, as well as (1.) on the next line. It's hard to get search results for such... concise syntax. Lisp must be from an era when the number of characters in a script was a limiting factor or something.

 

I've also been trying to get it to work with ssget instead of entsel, because I hate not being able to use box select, the minisucle selection window from entsel bothers my wrist. I've run into a wall with respect to getting the item type out of the selection set so that  the "car e" inside of wcmatch doesn't blow up. Does anyone know how to convert it to use ssget

0 Likes
Message 36 of 38

Sea-Haven
Mentor
Mentor

A simple example of top or bottom is in a closed pline it can be Clockwise or CounterClockwise, same with you line is it drawn left to right or right to left, if code did not look uses start and end points in its calc's the that would explain why bump is wrong way. So you can look at the angle and compare in each quadrant and if needed swap the end points. 

 

Lee-mac.com has a Text readable lisp you could look at how it handles the line angle and will swap it if needed.

0 Likes
Message 37 of 38

allwin_augustine
Participant
Participant

Bro,

 

Could you please redesign it with prompt for scaling of the jumper ?

0 Likes
Message 38 of 38

Kent1Cooper
Consultant
Consultant

@allwin_augustine wrote:

.... Could you please redesign it ....


[You should specify to which "it" you are referring.]

Kent Cooper, AIA
0 Likes