Author Topic: Help with code change on this lisp  (Read 2098 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Newt
  • Posts: 28
Help with code change on this lisp
« on: September 26, 2018, 02:34:36 PM »
I have this code below and it works but it only works if the insertion point selected is on a LINE...we generally draw with PLINE anyone know how to make it work with PLINE instead of Line?

Code: [Select]
(defun c:LJ ()
  (set_var_nil)
  (LINEJUMP)
  (princ)
)

(defun LINEJUMP ()
(setq LJ_L (entsel "Insertion Point: "))
(setq LJ_BLOCK (car LJ_L))
(setq LJ_N (entget LJ_BLOCK))
(setq LJ_I (nth 1 LJ_L))
(setq LJ_E1 (assoc 11 LJ_N))
(setq LJ_E2 (assoc 10 LJ_N))
(setq LJ_ep1 (nth 2 LJ_E1))
(setq LJ_ep2 (nth 2 LJ_E2))
(setq LJ_a (nth 0 LJ_I))
(setq LJ_b (nth 1 LJ_I))
(if (= LJ_ep1 LJ_ep2) (setq LJ_p2 (LIST (- LJ_a 1.0) LJ_b)))
(if (= LJ_ep1 LJ_ep2) (setq LJ_P3 (LIST (+ LJ_a 1.0) LJ_b)))
(if (/= LJ_ep1 LJ_ep2) (setq LJ_p2 (LIST LJ_a (- LJ_b 1.0))))
(if (/= LJ_ep1 LJ_ep2) (setq LJ_p3 (LIST LJ_a (+ LJ_b 1.0))))
(command "BREAK" LJ_I "F" LJ_p2 LJ_p3)
(if (= LJ_ep1 LJ_ep2) (command "INSERT" "LINEJUMP" LJ_I "1" "1" "0" ""))
(if (/= LJ_ep1 LJ_ep2) (command "INSERT" "LINEJUMP" LJ_I "1" "1" "90" ""))
(princ)
)

(defun set_var_nil()
  (mapcar
    '(lambda (x)
       (if (wcmatch (strcase x T) "LJ_*")
    (set (read x) nil)
       )
     )
    (atoms-family 1)
  )
  )

Thanks, in advance!


ribarm

  • Gator
  • Posts: 3180
  • Marko Ribar, architect
Re: Help with code change on this lisp
« Reply #1 on: September 26, 2018, 04:35:39 PM »
Your code tells that you use this on horizontal and vertical lines... Is this always the case - I mean if you need to apply it to LWPOLYLINE - it will always be orthogonal? Next thing, you are nil-ing variables before they are declared and not after - is this OK? I'd avoid your way of localization as you may accidentally nil some globals that start with LJ_ and you need them resident for some unknown reason declared if you plan to use them in starting session and you have them set by automatic load procedure when that session starts...

I would suggest you also that you specify gap that'll be used rather then hardcode it in routine as 1.0 - always...
If your LWPOLYLINE is orthogonal you can acquire segment start/end points by using (vlax-curve-getpointatparam) function applied on LW-ename and by providing parameters of beginning segment using (fix (vlax-curve-getpramatpoint lw-ename (vlax-curve-getclosestpointto lw-ename pick-point))) and ending segment parameter (1+ (fix ... =||= ...)). Rest of procedure after getting segment points is the same as with line entity - you just for calculations use instead of start/end points of line, start/end points of LWPOLYLINE segment you picked... And better make sure you use some osnaps for measuring precisely where you want to pick insertion point - (setq pt (getpoint)) function in combination with (nentselp pt) is for me better than (entsel) like in your case...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1378
  • 40 + years of using Autocad
Re: Help with code change on this lisp
« Reply #2 on: September 26, 2018, 11:38:20 PM »
Here is an example of what ribarm is talking about using "intersectwith" to work out where a pline needs to be trimmed this is a footpath pedestrian ramp 4 picks and done.

A man who never made a mistake never made anything

AVCAD

  • Newt
  • Posts: 28
Re: Help with code change on this lisp
« Reply #3 on: October 16, 2018, 01:52:39 PM »
Your code tells that you use this on horizontal and vertical lines... Is this always the case - I mean if you need to apply it to LWPOLYLINE - it will always be orthogonal? Next thing, you are nil-ing variables before they are declared and not after - is this OK? I'd avoid your way of localization as you may accidentally nil some globals that start with LJ_ and you need them resident for some unknown reason declared if you plan to use them in starting session and you have them set by automatic load procedure when that session starts...

Yes the lines will always be straight. This routine is used with a system diagram drawings and everything is on set parameters like snaps and ortho

the routine works exactly how i want it to work with the exception of, the line...we draw with polylines not line and for some reason this routine will not work if i select a polyline.

BIGAL

  • Swamp Rat
  • Posts: 1378
  • 40 + years of using Autocad
Re: Help with code change on this lisp
« Reply #4 on: October 17, 2018, 03:57:44 AM »
You need to post a dwg or an image to explain more what it is your trying to do.
A man who never made a mistake never made anything