Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoCAD PID component coding automation with LSP and DCL

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
wouter_klootwijk
417 Views, 4 Replies

AutoCAD PID component coding automation with LSP and DCL

Hello! I am working on a code to insert a block into my drawing. When the user uses the command “ETP_PID,” a dialog appears. In this dialog, the user can select a name of a DWG (first column in DCL code). When the user clicks on “OK,” the selected block should be inserted.

 

However, my code only works when the block has already been inserted in the drawing previously. My wish is that the code looks up the block name in my “support file search paths.”

 

Can anyone help? I hope my problem/question isn't too specific.

Labels (2)
4 REPLIES 4
Message 2 of 5
MrJSmith
in reply to: wouter_klootwijk

Your problem is you are using vla command to insert the block. VLA command is only referencing the current document object as seen here "(vla-insertblock (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))".

 

There are two options: 

  1. "Steal" the block first from the drawing it resides in. Lee Mac has a very good function to use for this task; however, you have to explicitly pass it the drawing the block resides in which then wouldn't use the support paths to look for the block. https://www.lee-mac.com/steal.html
  2. Another option is to use the autocad command "insert" which will trigger a search for the block based on support paths. Here is my "vlaMakeBlock" function that does just that.

 

(defun vlaMakeBlock (blockName layerName pt DS Rotation / blk) ;entMake a block with its name, layer, location, Rotation (rads), scale.
	(if (not (tblobjname "block" (cadr (fnsplitl blockName))))
		(progn
			(notify "Making Block")
			(layerExists layerName)
			(command "-insert" blockName 1 1 1 0)
			(entdel (entlast))
		)
	)
	(layerExists layerName)
	(setq blk (vla-insertblock (vlax-get-property *acdoc* (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace)) (vlax-3D-point pt) blockName DS DS 1.0 rotation))
	(vla-put-layer blk layerName)
	blk

)

 

Basically you just need call "(command "-insert" blockName 1 1 1 0)" then delete it with "(entdel (entlast))" and then you can use your vla command to insert it as the block reference would then be in the document.

 

Message 3 of 5

I add this function to check for block if in dwg or can be located in support path for insert:

; function to locate block
; returns nil if not found
(defun findblk (nam-arg / attreq flg)
 (if(not (setq flg (tblsearch "BLOCK" nam-arg))) ; look in block table
   (if(setq flg (findfile (strcat nam-arg ".dwg"))) ; look in support path
    (progn ; found
      (setq attreq (getvar"attreq")) ; save setting
      (setvar "attreq" 0) ; disable attribute dialog
      (vl-cmdf"_.Insert" flg "0,0,0" "" "" "")
      (entdel (entlast)) ; delete the insert
      (setvar "attreq" attreq) ; restore setting
    ) ; progn
   ) ; if
 ) ; if
 flg
)

Then include the function to check for the block here:

  ; Check of ETP_PID_LST3 is ingesteld en voer de blokinvoeging uit als dat zo is
  (if (and ETP_PID_LST3 (not (equal ETP_PID_LST3 "0")))
      (progn
; check if block is in dwg or can be inserted
(if (findblk (strcat "ETP-PID-" (nth (atoi LST3) LIJST3)))
 (progn
	(vla-insertblock (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
		 		 (vlax-3d-point (getpoint "\Pick point to insert block: "))
		 		 (strcat "ETP-PID-" (nth (atoi LST3) LIJST3)) 
		 		 1 1 1 0
	)
	(setpropertyvalue (entlast) "Code" (strcat (nth (atoi LST1) LIJST1) "" (nth (atoi LST2) LIJST2) "" (nth (atoi LST5) LIJST5) "" (nth (atoi LST4) LIJST4)))
        (princ "\nBlock inserted.")
 ) ; progn
 (princ (strcat "\nBlock: [ETP-PID-" (nth (atoi LST3) LIJST3) "] Not Found in current drawing or in AutoCAD support path."))
)  ; if
;
      )
  ) ; if

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 5

Thanks! This works for me.
Message 5 of 5

Glad to have helped…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report