offset more then 1 polyline

offset more then 1 polyline

Anonymous
Not applicable
1,389 Views
11 Replies
Message 1 of 12

offset more then 1 polyline

Anonymous
Not applicable

Hello,

 

i have an issue i want to make a lisp command to offset 2 polylines as an example i have a picture below.

the first are the polylines i need to offset. the second part is what i can get with a lisp i found online and the third picture is what i actually want.

lisp.PNGthe lisp i use for the bottom part is as follows:

(defun c:r4test ( / savesnap)
(setq ent (car (entsel "\nSelect polyline to offset: "))
pt (getpoint "\nSelect side to offset: "))
(foreach i '(distance 1 distance 2 distance 3 (command "._offset" i ent pt "")))

 

because i don't really know how to write these lisps i tried to add some for the line at the top. It seems not to be working and i cant really find an answer so far.

 

could someone explain what i would need to add to this lisp to also offset the top polyline?

 

0 Likes
Accepted solutions (1)
1,390 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

Ok, those purple ones, are they just different in color or on a different layer?

Always post a dwg then we don't need to ask these ridiculous questions.

 

Edit: Ok, you might not be able to. Then post on some other public cloud and post just a link.

0 Likes
Message 3 of 12

clindner
Advocate
Advocate

@Anonymous,

 

Try this:

(defun c:r4test (/ ent pt i)
  (setq ent (car (entsel "\nSelect polyline to offset: "))
	pt (getpoint "\nSelect side to offset: "))
  (foreach i '(1 2 3)
    (command "._offset" i ent pt "")
    ;; if i is odd, change color to magenta
    (if (/= 0 (rem i 2)) ; is i an even number
      (command "CHPROP" (entlast) "" "C" "6" "")
      )
    )
  (princ)
  )

This changes every other offset line to color 6, leaving the original entity alone. Did you want the selected pline changed to magenta?

 

Also, this code only offsets in one direction. 

 

HTH.

 


Please use the Accept as Solution or Kudo buttons when appropriate

Chris Lindner
CAD Technology Consultant @ onebuttoncad.com
AUGI Board of Directors

0 Likes
Message 4 of 12

Anonymous
Not applicable

Sorry i am new to this forum the purple lines are just a different colour.

0 Likes
Message 5 of 12

Anonymous
Not applicable

Thanks i tried your code it does change the colours but not the  right polylines. i do have to say thats not the main issue is wanted to solve. but i appreciate the help. 

 

This is the first time i am trying to create a lisp so I can't say i know excactly what i am doing but as far as i have it now it works perfectly for the offsets at the bottom polyline. 

0 Likes
Message 6 of 12

ВeekeeCZ
Consultant
Consultant

The first one.

 

(defun c:r2b ( / ensel)

  (if (and (setq ensel (entsel "\nSelect polyline to offset: "))
	   (or *2rb-dist*
	       (setq *2rb-dist* (abs (getvar 'OFFSETDIST))))
	   (setq *2rb-dist* (cond ((getdist (strcat "\nSpecify distance <" (rtos *2rb-dist*) ">:")))
				  (*2rb-dist*)))
	   )
    (command "_.offset" *2rb-dist*
	     (car ensel) (polar (cadr ensel) (* pi 0.5) *2rb-dist*)
	     (car ensel) (polar (cadr ensel) (* pi 1.5) *2rb-dist*)
	     ""
	     "_.chprop" (car ensel) "" "_C" "Magenta" ""))
  (princ)
)
0 Likes
Message 7 of 12

clindner
Advocate
Advocate

@Anonymous wrote:

Thanks i tried your code it does change the colours but not the  right polylines.

Ok, maybe this will.

(defun c:r4test (/ ent pt i)
  (setq ent (car (entsel "\nSelect polyline to offset: "))
	pt (getpoint "\nSelect side to offset: "))
  (foreach i '(1 2 3)
    (command "._offset" i ent pt "")
    ;; if i is odd, change color to magenta
    (if (= 0 (rem i 2)) ; is i an even number
      (command "CHPROP" (entlast) "" "C" "6" "")
      )
    )
  (command "CHPROP" ent "" "C" "6" "")
  (princ)
  )

 

@Anonymous wrote:

i do have to say thats not the main issue is wanted to solve  

 Maybe we should start there! 🙂 What is the "main issue"?

 

The code I've provided will generate the results shown on the bottom right of your screenshot. If you also want the option to generate what's shown in the top right, then we need to consider how the user will choose which one they want.

 


Please use the Accept as Solution or Kudo buttons when appropriate

Chris Lindner
CAD Technology Consultant @ onebuttoncad.com
AUGI Board of Directors

0 Likes
Message 8 of 12

Anonymous
Not applicable

I will try to explain what I think the lisp should do.

I have 2 polylines 1 above the other.

The bottom polyline has to offset 20 42.5 and 65 mm down

and the top polyline has to offset 22.5 up and down. 

The part of the bottom polyline is working fine. I need to add code for the top polyline.

0 Likes
Message 9 of 12

ВeekeeCZ
Consultant
Consultant
Accepted solution
(defun c:R4 ( / *error* osm pt1 pt2 ss)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if osmode (setvar 'OSMODE))
    (princ))
  
  (setq osm (getvar 'OSMODE))
  (setvar 'OSMODE 0)
  
  (if (and (setq pt1 (getpoint "\nSpecify point below bottom: "))
	   (setq pt2 (getcorner pt1 "\nSpecify point above upper: "))
	   (setq ss (ssget "_F" (list pt1 pt2)))
	   )
    (command "_.offset" 22.5
	     (ssname ss 1) pt1
	     (ssname ss 1) pt2
	     ""
	     "_.chprop" (ssname ss 1) "" "_C" "Magenta" ""
	     "._offset" 20 (ssname ss 0) pt1 ""
	     "._offset" 42.5 (ssname ss 0) pt1 ""
	     "_.chprop" "_Last" "" "_C" "Magenta" ""
	     "._offset" 65 (ssname ss 0) pt1 ""
	     "_.chprop" (ssname ss 0) "" "_C" "Magenta" ""))
  (*error* "end")
  )

 

 Edit: Routine was turning off osnaps and never get it back. Fixed now.

0 Likes
Message 10 of 12

clindner
Advocate
Advocate

That helps.

 

It's definitely doable but would require a little more time that I can commit for developing at this point. Sorry.

 

I'm anxious to see what solution you end up with.

 


Please use the Accept as Solution or Kudo buttons when appropriate

Chris Lindner
CAD Technology Consultant @ onebuttoncad.com
AUGI Board of Directors

0 Likes
Message 11 of 12

Anonymous
Not applicable

Hello BeekeeCZ,

 

Thank you very much it looks like this is excactly what i needed. I will run some tests with it later. 

 

Kind regards,

 

Bas

0 Likes
Message 12 of 12

marko_ribar
Advisor
Advisor

Actually, you haven't fixed it correctly...

In error handler, it should be instead of :

(if osmode (setvar 'OSMODE))

like this :

(if osm (setvar 'OSMODE osm))

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)