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

how to draw a polyline parallel to another polyline with autolisp code

17 REPLIES 17
Reply
Message 1 of 18
ahmet471985
3885 Views, 17 Replies

how to draw a polyline parallel to another polyline with autolisp code

i want create alisp to my user draw a polyline to parallel another polyline.is there any example for this.

17 REPLIES 17
Message 2 of 18
paullimapa
in reply to: ahmet471985

How about if you just Offset the specifi Polyline then you'll have a parallel?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 18
Lee_Mac
in reply to: ahmet471985

Or align the UCS with the source polyline & enable Orthomode.

Message 4 of 18
Kent1Cooper
in reply to: ahmet471985

I think we could use an image or a sample drawing.  People are assuming different things about what you are trying to do.  The Offset suggestion from pli will give you one that's parallel and the same distance away from the original everywhere, but "parallel" wouldn't necessarily mean at the same distance.  Lee_Mac's suggestion would give you parallel at perhaps varying distances, if the original is a single line segment or all line segments that are parallel and/or perpendicular to each other, but wouldn't help with an original that has non-perpendicular angles or arc segments.

Kent Cooper, AIA
Message 5 of 18
ahmet471985
in reply to: Kent1Cooper

Hello firstly thanks you for your answers.i am writing a program for electrical drawing.therefore my program users need line drawing.So i want to create a program that users can draw lines 5 unit distance from walls and line must be parallel to walls.but how can i provide my user draw a continously polyline but this polyline parallel to walls and 5 units distance from walls.
Please lee-mac write an example for your answer.
Thanks alot
Message 6 of 18
smaher12
in reply to: ahmet471985

I thinking why not use multiline or mline?

Message 7 of 18
ahmet471985
in reply to: Lee_Mac

I used (command "ucs" "ob" obj) for align ucs to object but for polyline only one side of polyline aligned.

how to align for other sides?

or is there any way align ucs to object without using (command "ucs")

 

 

Message 8 of 18
Kent1Cooper
in reply to: ahmet471985


@ahmet471985 wrote:
.... users can draw lines 5 unit distance from walls and line must be parallel to walls.but how can i provide my user draw a continously polyline but this polyline parallel to walls and 5 units distance from walls. ....

....

I can imagine a routine that would do that.  It would ask the User to select a Line representing a wall, and a side on which to Offset it, then would Offset it by 5 units and change it to another Layer, and for the first such Offset, convert it to a Polyline.  It would continue to ask for Line and side selections, and for the rest of the Offsets, Fillet the new Line with the Polyline that's already there, so that they are all joined together as it goes along.  If that sounds like a workable approach, I think it could be worked out.  It would not, however, be able to include Arcs as wall elements, since you can't Fillet an Arc with a Polyline.

Kent Cooper, AIA
Message 9 of 18
ahmet471985
in reply to: Kent1Cooper

Thank you for your information.I want to ask you a question can be join arc and polyline?

Message 10 of 18
ahmet471985
in reply to: Kent1Cooper

And also can i draw parallel to blocks for only one side of a block

Message 11 of 18
rapidcad
in reply to: ahmet471985

Based on the message thread, I am assuming that you are trying to write program solutions to automate some electrical wiring layouts for users. If the endpoints are coincident, you can just pedit join them, but if they are not, you can often convert the arc to a polyline and fillet the two polyline segments together, if they would intersect properly, that is. Using commands, this is a fairly straightforward process, but writing programming that covers all possible scenarios of this kind of fillet is more difficult.

ADN CAD Developer/Operator
Message 12 of 18
rapidcad
in reply to: ahmet471985

Would it work in your situation to offset just a line, arc, circle or polyline from a block the user chooses? A friend on this forum helped me greatly a few years ago by writing a program to offset entities from within a block without exploding the block, kind of like the express tool "Nest" does for copying entities out of blocks. I think you could use a modified version to offset a side of one of your blocks and then modify the resulting entity as you see fit. I can post it if it helps.

ADN CAD Developer/Operator
Message 13 of 18
ahmet471985
in reply to: rapidcad

rapidcad please wrote here your lisp for offset one side of blocks.Or send my e-mail:a_celil@hotmail.com.tr

I think also i can convert other objects to lwpolylines.After converting i can fillet. I found a lisp for converting..

Message 14 of 18
rapidcad
in reply to: ahmet471985

Here's the lisp to offset entities out of a block - written my Mel Franks back in"07. Mel made this for me to offset to a layer called "Detail" (or maybe I added that part myself?). Anyway, you can take that part out or change the layer if you need to.

 

For some wierd reason, the add attachment button below will not allow me to upload the lisp file claiming "The contents of the attachment doesn't match its file type" which is not true. Never had this problem before, so anyway I'll paste it in and you can copy it to a blank file and save it as OSB.lsp

 

;;OFFSET ENTITIES FROM BLOCK OBJECTS AND
;;PUT THEM ON LAYER DETAIL AND "BYLAYER"
;;BY MEL FRANKS FOR RAPIDCAD 11-14-07

(defun c:OSB (/ *error* z blk cmd-sv os-sv)

  (defun *error* (errmsg / x)
    (princ "Error: ")
    (princ errmsg)
    (setvar 'cmdecho cmd-sv)
    (setvar 'osmode os-sv)
    (if	#blk-ent-lst#
      (foreach x #blk-ent-lst#
	(if (not (vlax-erased-p x))
	  (vla-delete x)
	)
      )
    )
    (if	#off-obj#
      (if (not (vlax-erased-p #off-obj#))
	(vla-delete #off-obj#)
      )
    )
    (princ)
  )

  (vl-load-com)
  (setq	cmd-sv	      (getvar "cmdecho")
	os-sv	      (getvar "osmode")
	#blk-ent-lst# '()
	#off-obj#     nil
  )
  (setvar 'cmdecho 0)
  (setvar 'osmode 0)

  (if (not (tblsearch "layer" "DETAIL"))
    (vl-cmdf "_.layer" "n" "DETAIL" "")
  )
  (if (not (tblsearch "layer" "HIDDEN_BLOCK"))
    (vl-cmdf "_.layer" "n" "HIDDEN_BLOCK" "")
  )
  (vl-cmdf "_.layer" "f" "HIDDEN_BLOCK" "")
  (if (null #off-dist#)
    (setq #off-dist# 0.375)
  )
  (initget 6)
  (setq	x (getdist
	    (strcat "\nOffset distance: <" (rtos #off-dist#) "> ")
	  )
  )
  (if x
    (setq #off-dist# x)
  )
  (while (setq z (entsel "\nSelect object to offset: "))
    (cond
      ((setq blk (get-valid-object z))
       (setq #off-obj# (get-offset-obj blk))
       (initget 1)
       (setq dest (getpoint "\nSelect point on side to offset: "))
       (vl-cmdf	"_.offset"
		#off-dist#
		(vlax-vla-object->ename #off-obj#)
		dest
		""
       )
       (vl-cmdf	"_.chprop"
		(entlast)
		""
		"la"
		"DETAIL"
		"c"
		"BYL"
		"lt"
		"BYL"
		""
       )
       (vla-delete #off-obj#)
      )
    )
  )
  (setvar 'cmdecho cmd-sv)
  (setvar 'osmode os-sv)
  (princ)
)

					;function to get initial offset object
					;accepts return value from (entsel)
					;
(defun get-offset-obj (e / obj point-on-obj o-obj x orig-layer m)
  (setq	obj	      (vlax-ename->vla-object (car e))
	point-on-obj  (osnap (cadr e) "nea")
	#blk-ent-lst# (vlax-invoke obj 'Explode)
	o-obj	      nil
	orig-layer    (cdr (assoc 8 (entget (car e))))
  )
  (vl-cmdf "_.chprop" (car e) "" "la" "hidden_block" "")
  (setq m (nentselp point-on-obj))
  (vl-cmdf "_.chprop" (car e) "" "la" orig-layer "")
  (setq	m     (ck-for-vertex (car m))
	o-obj (vla-copy (vlax-ename->vla-object m))
  )
  (foreach x #blk-ent-lst# (vla-delete x))
  o-obj
)

					;if a vertex (polyline) is found
					;get base ename
					;
(defun ck-for-vertex (p / v)
  (setq v nil)
  (if (= (cdr (assoc 0 (entget p))) '"VERTEX")
    (while (and	(setq p (entnext p))
		(/= (cdr (assoc 0 (setq v (entget p)))) '"SEQEND")
	   )
    )
  )
					;return pline ename or just return input
  (if v
    (cdr (assoc -2 v))
    p
  )
)

					;get a valid block or single entity
					;accepts return value from (entsel)
					;
(defun get-valid-object	(ent / sub-ent sub-type flag nlst last-ent)
  (setq flag nil)
  (cond
    ((and
       (= (vla-get-objectname
	    (setq obj (vlax-ename->vla-object (car ent)))
	  )
	  "AcDbBlockReference"
       )
       (vlax-method-applicable-p obj 'explode)
       (equal
	 (vla-get-XScaleFactor obj)
	 (vla-get-YScaleFactor obj)
	 (vla-get-ZScaleFactor obj)
       )
     )
     (setq sub-ent (vlax-ename->vla-object
		     (car (setq nlst (nentselp (cadr ent))))
		   )
	   sub-typ (vla-get-objectname sub-ent)
     )
     (if (member sub-typ
		 '("AcDb2dVertex"     "AcDbPolyline"
		   "AcDbArc"	      "AcDbLine"
		   "AcDbCircle"	      "AcDbSpline"
		   "AcDbEllipse"
		  )
	 )
       (if (< (length (last nlst)) 2)
	 (setq flag ent)
	 (princ "\nCannot offset from a nested block")
       )
       (princ "\nThis object cannot be offset")
     )
    )
    (t
     (if (vlax-method-applicable-p
	   (vlax-ename->vla-object (car ent))
	   'offset
	 )
       (progn
	 (initget 1)
	 (setq dest	(getpoint "\nSelect point on side to offset: ")
	       last-ent	(entlast)
	 )
	 (vl-cmdf "_.offset" #off-dist# (car ent) dest "")
	 (if (not (eq last-ent (entlast)))
	   (vl-cmdf "_.chprop"
		    (entlast)
		    ""
		    "la"
		    "DETAIL"
		    "c"
		    "BYL"
		    "lt"
		    "BYL"
		    ""
	   )
	 )
       )
       (princ "\nThis object cannot be offset")
     )
    )
  )
  flag
)
(princ)

 

ADN CAD Developer/Operator
Message 15 of 18
rapidcad
in reply to: rapidcad

Just to give credit - now that I look at the very nice coding - I know Mel wrote it all for me. Thanks again Mel! I didn't grasp any vlisp back then.

ADN CAD Developer/Operator
Message 16 of 18
ahmet471985
in reply to: rapidcad

Thank you Ronald.

 

 

Abdulcelil DOĞAN

Electrical Engineer
Manager of Falco Engineering

Mardin city / Turkey

 

Message 17 of 18
rapidcad
in reply to: ahmet471985

Glad I could help - just sharing what others have blessed me with.

Ron

ADN CAD Developer/Operator
Message 18 of 18
btlsp2014
in reply to: ahmet471985

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

Post to forums  

Autodesk Design & Make Report

”Boost