Need Assistance with Modifying LISP Routine

Need Assistance with Modifying LISP Routine

Anonymous
Not applicable
722 Views
5 Replies
Message 1 of 6

Need Assistance with Modifying LISP Routine

Anonymous
Not applicable

Hi All,

 

I am hoping someone can make a quick modification to the below LISP routine. The current routine does the following:

 

  1. Prompts user to select a polyline
  2. Creates a region from the polyline while still keeping the existing polyline in place
  3. Adds our room tag block to the center of the region
  4. Associates the room sf field in the block with the area of the region

I need to make the routine a little bit smarter. I would like the following:

 

  1. Prompts the user to select if they will be using a polyline or a region
  2. LISP would have two possible outcomes
    • If polyline option is selected:
      1. Prompts user to select a polyline
      2. Adds our room tag block to the center of the polyline
      3. Associates the room sf field in the block with the area of the polyline
    • If the region option is selected (same as existing LISP):
      1. Prompts user to select a polyline
      2. Creates a region from the polyline while still keeping the existing polyline in place
      3. Adds our room tag block to the center of the region
      4. Associates the room sf field in the block with the area of the region
  3. Prompts user to enter room number and populates room number field in block.

Bonus points if you can get the LISP to pull the block from our design center. You can just put a placeholder for the file path and I will fill it in. Also a bonus if you add comments for each part of the LISP routine explaining what it is doing. I'd like to get a better understanding so I can start making these modifications myself. However, it is not required.

 

I am attaching the LISP routine and a drawing with the room tag block. I really appreciate any assistance anyone can offer.

 

Thank you!

0 Likes
723 Views
5 Replies
Replies (5)
Message 2 of 6

hak_vz
Advisor
Advisor

@Anonymous 

If you don't have curved walls in your drawings,  creating region is not strictly necessary. Calculation of polygon centroid is simple and it is average of sum of all polyline vertexes.

 

(defun C:Tag  (/ pickObj ms tagArea room tag centroid)
	(vl-load-com)
	(defun centroid (e / take pointlist2d pts cpt n e)
		(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
		(defun pointlist2d (lst / ret) (while lst (setq	ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
		(setq pts (pointlist2d (vlax-get (vlax-ename->vla-object e) 'Coordinates)) n (length pts))
		(setq cpt '(0 0) n (float(length pts)))
		(while (and pts)(setq cpt (mapcar '+ cpt (car pts)) pts (cdr pts)))
		(mapcar '/ cpt  (list n n))
	)
		(setvar "ErrNo" 0)
	(while (and (not (setq pickObj (car(entsel "\nSelect room: "))))
			 (/= 52 (getvar "ErrNo"))))
	(cond
		((and pickObj)
		  (setq ms      (vla-Get-ModelSpace (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
				tagArea "A-Rmblk"
				blkSF   (getvar "DimScale")
				blkRot  0.0
			)
		  (tblsearch "Block" tagArea)
		  (setq tag (vla-InsertBlock ms
									(vlax-3D-Point (append (centroid pickObj) '(0.0)))
									 tagArea
									 blkSF
									 blkSF
									 blkSF
									 blkRot))
		  (vla-Put-TextString
		   (nth 1 (vlax-Invoke tag 'GetAttributes))
		   (strcat "%<\\AcObjProp Object("
				   (itoa (vla-Get-ObjectID (vlax-ename->vla-object pickObj)))
				   ").Area \\f \"%pr0%lu2%ct4%qf1\">%"))
		)
	)
	(command "_regen")
	(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.
Message 3 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... Bonus points if you can get the LISP to pull the block from our design center. ....


For that, just put the file-path location in the Support File Search Path list under the Files tab in the OPTIONS dialog box, and it will find it without the need to include the path in the routine.

Kent Cooper, AIA
Message 4 of 6

Anonymous
Not applicable

Thanks for your reply, @hak_vz

 

We need to use regions when subtracting out columns from our room areas. So the polyline option of the LISP will be for most rooms. The region option will be for rooms with curved walls or rooms where we need to subtract out "islands". We need to include polylines for each room as our GIS program uses that layer. Otherwise we would use regions only. 🙂

0 Likes
Message 5 of 6

Anonymous
Not applicable

Thanks for the reply, @Kent1Cooper .

 

I wouldn't need to modify the existing LISP any for this to work?

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Thanks for the reply, @Kent1Cooper .

I wouldn't need to modify the existing LISP any for this to work?


No, you shouldn't need to.  But try it -- I know you wouldn't need to if using  (command "_.insert" ...) , but it could be that  (vla-InsertBlock ...)  doesn't know enough to go looking in the Support File Search Path locations if the Block is not already defined in the drawing.  The  (vla-...)  functions are not in the AutoLisp Reference to look at what they need.

Kent Cooper, AIA
0 Likes