Identify the Command used in LISP

Amriya_Exe
Advocate
Advocate

Identify the Command used in LISP

Amriya_Exe
Advocate
Advocate

My requirement is want to how this attached lisp is functioning so I can also write/learn something like that as per my requirement. 

This LISP ask to select 9 points on downline and 9 points on upline when we use command "PLAN-AK" then add some custom blocks on that points with some formal/calculation.

Please Check VIDEO attached to see How this working. 

 

 

0 Likes
Reply
Accepted solutions (1)
733 Views
14 Replies
Replies (14)

john.uhden
Mentor
Mentor

@Amriya_Exe ,

It looks like it took you just over a minute.  Isn't that good enough?

John F. Uhden

0 Likes

Sea-Haven
Mentor
Mentor

Is red line a line or pline going through all points ? If so can use that to select 2 rows of points. If the points are created in sequence it looks like that then easy, if not can sort the points into correct order, that would take like 3 seconds then your splat answer,  maybe 10 seconds.

 

Please confirm. Hint (SSGET "F" pts '((0 . "POINT")))

0 Likes

Amriya_Exe
Advocate
Advocate

Yes that Polyline is going through all points.

For this example points in same sequence all at distance of 4.490m. but on actual work some will be at 4.985, 4.983, 4.992, something like that.

 

I want to know how it's working and I wanted to recreate my own version of it.

0 Likes

-didier-
Advisor
Advisor

Bonjour @Amriya_Exe 

 

It does not seem very difficult.
If I understand correctly, of course !

For example, what does it mean ? : on that points with some formal/calculation.

What kind of calculations?

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

Didier Aveline

EESignature

0 Likes

Kent1Cooper
Consultant
Consultant

@Amriya_Exe wrote:

My requirement is want to how this attached lisp is functioning ....


That is a .VLX file, which is a compiled format, and we can't get into it, to look at how it functions.  If you have access to the presumed AutoLisp .LSP file that it was compiled from, maybe we could advise you.

Kent Cooper, AIA
0 Likes

Amriya_Exe
Advocate
Advocate
I don't have LSP.
Cant we get some idea from the process to make similar?
0 Likes

Amriya_Exe
Advocate
Advocate
Calculation like there is insert of block "ej" which will be added on point number 3,5,7 on up line and similar on downline.
Insert Block Name "5m" on meddle of two points between 1&2, 2&3, 3&4, 5&6, 7&8.
Insert Block name "left-rc" on Point 1&9 of both line but on points 9 it will be rotated 180.
and after all these add dimension like showing in drawing.
0 Likes

hak_vz
Advisor
Advisor

@Amriya_Exe Attach resulting dwg file so we can rewrite the code you are looking for!

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes

Primerail01
Explorer
Explorer

Please find attachment.

0 Likes

hak_vz
Advisor
Advisor
Accepted solution

@Amriya_Exe  @Primerail01 

 

Here you have it. Check if everything is here!

 

 

(defun c:ppk( / *error* adoc ss points middlepoints i oldosm blk  evenp)
	;	author: Hak_vz 13.04.2024.
	;	https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5530556
	;	posted to
	; 	https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/identify-the-command-used-in-lisp/m-p/12706375#M464577
		
	(defun *error* ()
		(setvar 'cmdecho 1)
		(setvar 'osmode oldosm)
		(if (and adoc) (vla-endundomark adoc))
		(princ)
	)
	(defun evenp (num)(cond ((numberp num) (= (rem num 2.0) 0.0))))
	(princ "\nSelect points (they will auto order) >")
	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(setq ss (ssget '((0 . "POINT"))) i -1)
	(cond 
		((and ss (>= (sslength ss) 2))
			(setq oldosm (getvar 'osmode))
			(setvar 'osmode 0)
			(setvar 'cmdecho 0)
			(vla-endundomark adoc)
			(vla-startundomark adoc)
			(while (< (setq i (1+ i)) (sslength ss))
				(setq points (cons (cdr (assoc 10 (entget (ssname ss i)))) points))
		
			)
			(setq points (vl-sort points '(lambda (a b) (< (car a)(car b)))))
			(setq i -1)
			(while (< (setq i (1+ i)) (1- (length points)))
				(setq middlepoints (cons (mapcar '* '(0.5 0.5 0.0) (mapcar '+ (nth i points)(nth (1+ i) points))) middlepoints))
			)
			(setq middlepoints (vl-sort middlepoints '(lambda (a b) (< (car a)(car b)))))
			(setq blk 
				(vlax-invoke
					(vlax-get 
						(vla-item 
							(vla-get-layouts 
								(vla-get-activedocument (vlax-get-acad-object))) "MODEL" )
								'block
					)
					'InsertBlock
					(car points) "left-rc" 1 1 1 0
				)
			)
			(setq blk 
				(vlax-invoke
					(vlax-get 
						(vla-item 
							(vla-get-layouts 
								(vla-get-activedocument (vlax-get-acad-object))) "MODEL" )
								'block
					)
					'InsertBlock
					(last points) "L-SEMIANCHOR" 1 1 1 0
				)
			)
			(setq i 0)
			(while (< (setq i (1+ i)) (1- (length points)))
				(setq blk 
					(vlax-invoke
						(vlax-get 
							(vla-item 
								(vla-get-layouts 
									(vla-get-activedocument (vlax-get-acad-object))) "MODEL" )
									'block
						)
						'InsertBlock
						(nth i points) "FULL-ANCHOR" 1 1 1 0
					)
				)	
			)
			(foreach pt middlepoints
				(setq blk 
					(vlax-invoke
						(vlax-get 
							(vla-item 
								(vla-get-layouts 
									(vla-get-activedocument (vlax-get-acad-object))) "MODEL" )
									'block
						)
						'InsertBlock
						pt "5m" 1 1 1 0
					)
				)
			)
			(initget "U D")
			(setq opt (strcase(getkword "\nUpline or Downline <U D> >>")))
			(if (= opt "D") (setq dir -1)(setq dir 1))
			(setq i -1 k (mapcar '* (list 0 dir) '(0 2.0)))
			(while (< (setq i (1+ i)) (1- (length points)))
				(command "_.dimhorizontal" (nth i points)(nth (1+ i) points)(mapcar '+ (nth (1+ i) points) k))
			)
			(setq i -1 spt nil)
			(while (< (setq i (1+ i)) (length points))
				(cond
					((= i 0)(setq spt (cons (nth i points) spt)))
					((and (evenp i)(< i (1- (length points))))
						(setq spt (cons (mapcar '- (nth i points)'(0.005 0.0)) spt))
						(setq spt (cons (mapcar '+ (nth i points)'(0.005 0.0)) spt))
					)
					((= i (1- (length points)))(setq spt (cons (last points) spt)))
				)
				(cond
					((and (evenp i)(> i 0)(< i (1-(length points))))
						(setq blk 
							(vlax-invoke
								(vlax-get 
									(vla-item 
										(vla-get-layouts 
											(vla-get-activedocument (vlax-get-acad-object))) "MODEL" )
											'block
								)
								'InsertBlock
								(nth i points) "ej" 1 1 1 pi
						
							)
						)
					)
				)
			)
			(setq spt (reverse spt))
			(setq i -1)
			(setq i -1 k (mapcar '* (list 0 dir) '(0 3.0)))
			(while (< (setq i (1+ i)) (1- (length spt)))
				(command "_.dimhorizontal" (nth i spt)(nth (1+ i) spt)(mapcar '+ (nth (1+ i) spt) k))
			)
			(setq k (mapcar '* (list 0 dir) '(0 4.0)))
			(command "_.dimhorizontal" (car points)(last points)(mapcar '+ (last points) k))
			(setvar 'osmode oldosm)
			(setvar 'cmdecho 1)
			(vla-endundomark adoc)
		)
	)
	(princ "\nDone!")
	(princ)
)
(princ "\n Enter PPK to run!")
(princ)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes

Amriya_Exe
Advocate
Advocate

Thank you very much.
I try but after selecting points I getting this message.

I getting this error.

Block not getting aligned to line.

When I select the points auto detect number detecting my first point as last point so adding wrong block on last point and last block on first block.

and last its getting stopped when its ask bout Downline or Upline.

Amriya_Exe_0-1713072245844.png

 

0 Likes

hak_vz
Advisor
Advisor

@Amriya_Exe  See video on post #11 and take code. Not changed but added explanation for key selection for up down.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes

Amriya_Exe
Advocate
Advocate
Thank you 🙂

hak_vz
Advisor
Advisor

@Amriya_Exe 

 

Check if code needs some modifications regarding block orientations or scaling depending on the case (U D) and distance between marker points.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes