Jump to content

Recommended Posts

Posted

Dear All Masters,

 

I need two lisp programs one is Place lines as a stack with some minor offset. because my lines are merged.highest length of a line should be bottom or top and remaining lines are stacked by descending order by its length of line.please find attachment for clarity.

 

2nd lisp for length Labeling of a Poly lines or Ordinary lines with leader.please find attachment for clarity.

 

Please provide suitable Lisp code for this lengthy task for me.

 

Thanking you all.

Before converting.jpg

After  Converting.jpg

For Lisp Forum.jpg

Posted

Dear all Please respond to this task.anyone know how to finish this task?

Posted

Its about time to do and wether some one has something already they can quickly butcher together.

 

Its a basic lisp required made up of 3 bits

Using vlisp get the length

Work out the midpoint of the pline/line picked, work out the leader 2nd point, or do manually as a start.

Draw a leader.

 

(setq obj (vlax-Ename->Vla-Object (car (entsel))))
(setq len (rtos (vla-get-length obj) 2 3)) ; length as string

Posted
Its about time to do and wether some one has something already they can quickly butcher together.

 

Its a basic lisp required made up of 3 bits

Using vlisp get the length

Work out the midpoint of the pline/line picked, work out the leader 2nd point, or do manually as a start.

Draw a leader.

 

(setq obj (vlax-Ename->Vla-Object (car (entsel))))
(setq len (rtos (vla-get-length obj) 2 3)) ; length as string

 

 

Thank you for your valuable reply.

 

i have lines with overlapped and merged. so please do the code for separate the lines in y direction with small offset gap.without changing x coordinate values.

Posted (edited)

This?

; Grrr wrote it, but the credits should go to: Lee Mac, Tharwat
; labels lines, or open polylines by creating mleaders with content of their curve length:
(defun C:test ( / oldcmd SS ent vla-obj obj-length midpt dist ang )
(if
	(and
		(princ "\nSelect Lines or Open Polylines")
		(setq SS 
			(ssget "_:L" 
				(list (cons 0 "LINE,*POLYLINE"))
			)
		)
	);and
	(progn
		(setq oldcmd (getvar 'cmdecho))
		(setvar 'cmdecho 0)
		(initget (+ 1 2 4))
		(setq dist (getreal "\nSpecify mleader offset distance: "))
		(initget 1)
		(setq ang (getreal "\nSpecify mleader angle: "))
		(defun DtR (d) ( * PI (/ d 180.0)))
		(repeat (setq i (sslength SS)) ; iterate trought selection
			(setq ent (ssname SS (setq i (1- i)))) ; current entity
			(setq vla-obj (vlax-ename->vla-object ent))
			(if (not (vlax-curve-IsClosed ent))
				(progn
					(setq obj-length (vlax-curve-getDistAtPoint vla-obj (vlax-curve-getEndPoint vla-obj)))
					(setq midpt (vlax-curve-GetPointAtDist vla-obj (/ (vlax-curve-GetDistAtParam vla-obj (vlax-curve-GetEndParam vla-obj)) 2.)) )
					(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) "" (strcat (rtos obj-length 2 2) "m"))
				)
			)
			
		);repeat
		(setvar 'cmdecho oldcmd)
	);progn
)
(princ)
);defun	

Heres some dwg to test on:

test-label.dwg

 

EDIT:

Heres some more developed version, which allows graphical or analytical input for the mleaders (using the info from my thread Analyze Output ):

; Grrr wrote it, but the credits should go to: Lee Mac, Tharwat
; labels lines, or open polylines by creating mleaders with content of their curve length:
(defun C:test ( / oldcmd SS ent vla-obj obj-length midpt dist ang ans ans2 mode go )
(if
	(and
		(princ "\nSelect Lines or Open Polylines")
		(setq SS 
			(ssget "_:L" 
				(list (cons 0 "LINE,*POLYLINE"))
			)
		)
	);and
	(progn
		(defun DtR (d) ( * PI (/ d 180.0)))
		(defun RtD (r) (* 180.0 (/ r PI)))
		(setq oldcmd (getvar 'cmdecho))
		(setvar 'cmdecho 0)
		(setq mode 0)
		(setq go T)
		(initget 128 "Distance") ; allows all inputs
		(while go
			(setq ans (getpoint "\nSpecify first mleader reference point or [Distance]: "))
			(cond
				((= (type ans) 'LIST)
					(setq ans2 (getpoint "\nSpecify second mleader reference point: " ans))
					(setq ang (RtD (angle ans ans2)))
					(setq dist (distance ans ans2))
					(setq go nil)
				)
				((or (= ans "Distance") (= ans "D") (= ans "d") )
					(setq mode 1)
					(setq go nil)
				)
			)
		)
		
		(initget (+ 1 2 4))
		(if (= mode 1) (setq dist (getreal "\nSpecify mleader offset distance: ")) )
		(initget 1)
		(if (= mode 1) (setq ang (getreal "\nSpecify mleader angle: ")) )
		
		(repeat (setq i (sslength SS)) ; iterate trought selection
			(setq ent (ssname SS (setq i (1- i)))) ; current entity
			(setq vla-obj (vlax-ename->vla-object ent))
			(if (not (vlax-curve-IsClosed ent))
				(progn
					(setq obj-length (vlax-curve-getDistAtPoint vla-obj (vlax-curve-getEndPoint vla-obj)))
					(setq midpt (vlax-curve-GetPointAtDist vla-obj (/ (vlax-curve-GetDistAtParam vla-obj (vlax-curve-GetEndParam vla-obj)) 2.)) )
					(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) "" (strcat (rtos obj-length 2 2) "m"))
				)
			)
			
		);repeat
		(setvar 'cmdecho oldcmd)
	);progn
)
(princ)
);defun							

Edited by Grrr
Posted
This?

; Grrr wrote it, but the credits should go to: Lee Mac, Tharwat
; labels lines, or open polylines by creating mleaders with content of their curve length:
(defun C:test ( / oldcmd SS ent vla-obj obj-length midpt dist ang )
   (if
       (and
           (princ "\nSelect Lines or Open Polylines")
           (setq SS 
               (ssget "_:L" 
                   (list (cons 0 "LINE,*POLYLINE"))
               )
           )
       );and
       (progn
           (setq oldcmd (getvar 'cmdecho))
           (setvar 'cmdecho 0)
           (initget (+ 1 2 4))
           (setq dist (getreal "\nSpecify mleader offset distance: "))
           (initget 1)
           (setq ang (getreal "\nSpecify mleader angle: "))
           (defun DtR (d) ( * PI (/ d 180.0)))
           (repeat (setq i (sslength SS)) ; iterate trought selection
               (setq ent (ssname SS (setq i (1- i)))) ; current entity
               (setq vla-obj (vlax-ename->vla-object ent))
               (if (not (vlax-curve-IsClosed ent))
                   (progn
                       (setq obj-length (vlax-curve-getDistAtPoint vla-obj (vlax-curve-getEndPoint vla-obj)))
                       (setq midpt (vlax-curve-GetPointAtDist vla-obj (/ (vlax-curve-GetDistAtParam vla-obj (vlax-curve-GetEndParam vla-obj)) 2.)) )
                       (command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) "" (strcat (rtos obj-length 2 2) "m"))
                   )
               )
               
           );repeat
           (setvar 'cmdecho oldcmd)
       );progn
   )
   (princ)
);defun    

Heres some dwg to test on:

[ATTACH]58325[/ATTACH]

 

EDIT:

Heres some more developed version, which allows graphical or analytical input for the mleaders (using the info from my thread Analyze Output ):

; Grrr wrote it, but the credits should go to: Lee Mac, Tharwat
; labels lines, or open polylines by creating mleaders with content of their curve length:
(defun C:test ( / oldcmd SS ent vla-obj obj-length midpt dist ang ans ans2 mode go )
   (if
       (and
           (princ "\nSelect Lines or Open Polylines")
           (setq SS 
               (ssget "_:L" 
                   (list (cons 0 "LINE,*POLYLINE"))
               )
           )
       );and
       (progn
           (defun DtR (d) ( * PI (/ d 180.0)))
           (defun RtD (r) (* 180.0 (/ r PI)))
           (setq oldcmd (getvar 'cmdecho))
           (setvar 'cmdecho 0)
           (setq mode 0)
           (setq go T)
           (initget 128 "Distance") ; allows all inputs
           (while go
               (setq ans (getpoint "\nSpecify first mleader reference point or [Distance]: "))
               (cond
                   ((= (type ans) 'LIST)
                       (setq ans2 (getpoint "\nSpecify second mleader reference point: " ans))
                       (setq ang (RtD (angle ans ans2)))
                       (setq dist (distance ans ans2))
                       (setq go nil)
                   )
                   ((or (= ans "Distance") (= ans "D") (= ans "d") )
                       (setq mode 1)
                       (setq go nil)
                   )
               )
           )
           
           (initget (+ 1 2 4))
           (if (= mode 1) (setq dist (getreal "\nSpecify mleader offset distance: ")) )
           (initget 1)
           (if (= mode 1) (setq ang (getreal "\nSpecify mleader angle: ")) )
           
           (repeat (setq i (sslength SS)) ; iterate trought selection
               (setq ent (ssname SS (setq i (1- i)))) ; current entity
               (setq vla-obj (vlax-ename->vla-object ent))
               (if (not (vlax-curve-IsClosed ent))
                   (progn
                       (setq obj-length (vlax-curve-getDistAtPoint vla-obj (vlax-curve-getEndPoint vla-obj)))
                       (setq midpt (vlax-curve-GetPointAtDist vla-obj (/ (vlax-curve-GetDistAtParam vla-obj (vlax-curve-GetEndParam vla-obj)) 2.)) )
                       (command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) "" (strcat (rtos obj-length 2 2) "m"))
                   )
               )
               
           );repeat
           (setvar 'cmdecho oldcmd)
       );progn
   )
   (princ)
);defun                            

 

 

thank you for your reply. your code is not printed length of the pline it shows blank leader.

 

Sir,

please find below attachment and observe the lines of 1 & 2 Diagrams.

1 st diagram contains merged blue line. at 2nd diagram i have manually moved with move command with some distance. so kindly prepare the code for Merged to stacked lines.there is no change in X coordinates value, they are moved in Y Direction only kindly observe.

Auto lisp Code merged lines.dwg

Posted

Woops, sorry!

Thanks for mentioning this, this one should work:

; Grrr wrote it, but the credits should go to: Lee Mac, Tharwat
; labels lines, or open polylines by creating mleaders with content of their curve length:
(defun C:test ( / oldcmd SS ent vla-obj obj-length midpt dist ang ans ans2 mode go )
(if
	(and
		(princ "\nSelect Lines or Open Polylines")
		(setq SS 
			(ssget "_:L" 
				(list (cons 0 "LINE,*POLYLINE"))
			)
		)
	);and
	(progn
		(defun DtR (d) ( * PI (/ d 180.0)))
		(defun RtD (r) (* 180.0 (/ r PI)))
		(setq oldcmd (getvar 'cmdecho))
		(setvar 'cmdecho 0)
		(setq mode 0)
		(setq go T)
		(initget 128 "Distance") ; allows all inputs
		(while go
			(setq ans (getpoint "\nSpecify first mleader reference point or [Distance]: "))
			(cond
				((= (type ans) 'LIST)
					(setq ans2 (getpoint "\nSpecify second mleader reference point: " ans))
					(setq ang (RtD (angle ans ans2)))
					(setq dist (distance ans ans2))
					(setq go nil)
				)
				((or (= ans "Distance") (= ans "D") (= ans "d") )
					(setq mode 1)
					(setq go nil)
				)
			)
		)
		
		(initget (+ 1 2 4))
		(if (= mode 1) (setq dist (getreal "\nSpecify mleader offset distance: ")) )
		(initget 1)
		(if (= mode 1) (setq ang (getreal "\nSpecify mleader angle: ")) )
		
		(repeat (setq i (sslength SS)) ; iterate trought selection
			(setq ent (ssname SS (setq i (1- i)))) ; current entity
			(setq vla-obj (vlax-ename->vla-object ent))
			(if (not (vlax-curve-IsClosed ent))
				(progn
					(setq obj-length (vlax-curve-getDistAtPoint vla-obj (vlax-curve-getEndPoint vla-obj)))
					(setq midpt (vlax-curve-GetPointAtDist vla-obj (/ (vlax-curve-GetDistAtParam vla-obj (vlax-curve-GetEndParam vla-obj)) 2.)) )
					(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) (strcat (rtos obj-length 2 2) "m"))
				)
			)
			
		);repeat
		(setvar 'cmdecho oldcmd)
	);progn
)
(princ)
);defun							

I've had additional "enter" of the mleader command call - fixed.

Posted

I'm not sure what might the issue is, but the last edition I posted doesn't work on my uploaded drawing, but works on yours.

And the code in my #5 post works fine for me, but not for your dwg.

The only difference is this row:

(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) "" (strcat (rtos obj-length 2 2) "m"))

(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) (strcat (rtos obj-length 2 2) "m"))

And the difference in the dwg's that I've noticed is that you use "STANDARD" MLSTYLE, and mine is custom.

So one might want to change that row to this:

(cond
						((eq (strcase (getvar 'CMLEADERSTYLE)) "STANDARD" )
							(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) (strcat (rtos obj-length 2 2) "m"))
						)
						(T
							(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) "" (strcat (rtos obj-length 2 2) "m"))
						)
					)

And it will work fine.

Posted
I'm not sure what might the issue is, but the last edition I posted doesn't work on my uploaded drawing, but works on yours.

And the code in my #5 post works fine for me, but not for your dwg.

The only difference is this row:

(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) "" (strcat (rtos obj-length 2 2) "m"))

(command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) (strcat (rtos obj-length 2 2) "m"))

And the difference in the dwg's that I've noticed is that you use "STANDARD" MLSTYLE, and mine is custom.

So one might want to change that row to this:

(cond
                           ((eq (strcase (getvar 'CMLEADERSTYLE)) "STANDARD" )
                               (command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) (strcat (rtos obj-length 2 2) "m"))
                           )
                           (T
                               (command "_.MLEADER" "_non" midpt "_non" (polar midpt (DtR ang) dist) "" (strcat (rtos obj-length 2 2) "m"))
                           )
                       )

And it will work fine.

 

thank you sir, your code is good.but how to separate the lines? any code?

Posted
thank you sir, your code is good.but how to separate the lines? any code?

 

Sorry I did not noticed your second request. This is how I would approach it:

 

1. Specify spacing distance and direction Y+/Y-/X+/X- (or use getdistance)

1. Entsel the longest pline in the stack

2. Use the ssget "F" (fence method along its vertices)

3. Iterate trought selection, check if its pline on the same layer and construct a list of these entities sorted by their length

4. Move each element from the list, and increase the spacing distance (setq spacing (+ spacing spacing))

 

Unfortunately I don't know when I'll do that code as my desktop turned a big mess of .lsp files again, which I'm analysing...

Posted (edited)

So heres the code for your second request:

; Grrr wrote it, but the credits should go to: Lee Mac, Tharwat
; moves stacked plines from the same layer, by picking the longest of them, at a specified distance and angle
(defun c:test ( / ent ent2 pt dist spacing ang vla-obj vla-obj2 i vertlst SS obj-length)
(vl-load-com) ; load the visual lisp extensions
(setvar 'errno 0)
(while T
	(while
		(not
			(and
				(setq ent (entsel "\nSelect the longest Polyline from the stack: ")) ; get the entity and entity name
				(wcmatch (strcase (cdr (assoc 0 (entget (car ent))))) "*POLYLINE*")
			)
		)
		(if (or (= (getvar 'errno) 7) (null ent) ) (princ "\nMissed, try again!"))
	)
	
	(setq pt (getpoint "\nSpecify spacing distance, and angle: " (cadr ent) ))
	; work out the vector:
	(setq dist (distance (cadr ent) pt))
	(setq ang (angle (cadr ent) pt))
	
	(setq vla-obj (vlax-ename->vla-object (car ent))) ; convert to vl object
	
	(if (= (vlax-get-property vla-obj 'ObjectName) "AcDbPolyline") ; check if it's a polyline	
		(progn
			; vertices list:
			(setq vertlst (Get-Poly-Vertl (car ent)))
			(setq SS (ssget "_F" vertlst (list (cons 8 (cdr (assoc 8 (entget (car ent))))))))
			(if (not spacing) (setq spacing 0) )
			(setq i 0)
			(repeat (sslength SS) ; iterate trought selection
				(setq ent2 (ssname SS i)) ; current entity
				(setq vla-obj2 (vlax-ename->vla-object ent2))
				(if (not (vlax-curve-IsClosed ent2))
					(progn
						(setq obj-length (vlax-curve-getDistAtPoint vla-obj2 (vlax-curve-getEndPoint vla-obj2)))
						; (print obj-length)
					)
				)
				(vla-Move vla-obj2 (vlax-3D-point (cadr ent)) (vlax-3D-point (polar (cadr ent) ang spacing)))
				(setq spacing (+ spacing dist))
				(setq i (1+ i))
			);repeat
			; (sssetfirst nil SS)
			; (print vertlst)
			(setq spacing nil)
		)
	)
)
(princ)
)


; Poly-Pts (gile)
; Returns the vertices list of any type of polyline (WCS coordinates)
(defun Get-Poly-Vertl (pl / pa pt vertlst)
(setq pa 
	(if (vlax-curve-IsClosed pl)
		(vlax-curve-getEndParam pl)
		(+ (vlax-curve-getEndParam pl) 1)
	)
	)
	(while (setq pt (vlax-curve-getPointAtParam pl (setq pa (- pa 1))))
		(setq vertlst (cons pt vertlst))
	)
)																		

It doesn't work exactly as I described in my previous post (the entities are NOT sorted by their obj length, so sometimes there might be unwanted results) - couldn't figure that out. And perhaps the code could be shortened.

Still it serves its purpose.

Edited by Grrr

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...