Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert block lisp

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
2939 Views, 5 Replies

Insert block lisp

Hello,

I am beginer at making lisp's, but the thing I need is lisp for inserting two blocks. First one from current drawing its not a problem. Second will be one of ~300 blocks, probably from some folder on server. I cant manage to find a right function or the right way how to specifie the folder where to look for blocks.

 

What I am trying to do:

Command "CZ"

specify first (block1) block location

specify angle

write block number second (block2) block

specify location

specify angle

 

(DEFUN c:cz()
(COMMAND "INSERT"
"Block1"
"S"
(SETQ sc (GETVAR "dimscale"))
(GETPOINT "Block 1 location")
pause
)
(setq p1 (getstring "\nBlock2 number: "))
(COMMAND "INSERT"
p1

XXXXX      problem is here dont know how to write command, for Autocad to look fow *.dwg file in certain folder (ex. S:\Projekti\Saldus aplis\Blocks)
"S"
(SETQ sc (GETVAR "dimscale"))
(GETPOINT "Block2 location")
pause
)
)

 

P.S. would really appreciate explanation not just solution, want to understand this thing.

Thank you in advance.

5 REPLIES 5
Message 2 of 6
tmccar
in reply to: Anonymous

Can you try like this:

 

JanisM_LV wrote:

Hello,

I am beginer at making lisp's, but the thing I need is lisp for inserting two blocks. First one from current drawing its not a problem. Second will be one of ~300 blocks, probably from some folder on server. I cant manage to find a right function or the right way how to specifie the folder where to look for blocks.

 

What I am trying to do:

Command "CZ"

specify first (block1) block location

specify angle

write block number second (block2) block

specify location

specify angle

 

(DEFUN c:cz()
(COMMAND "INSERT"
"Block1"
"S"
(SETQ sc (GETVAR "dimscale"))
(GETPOINT "Block 1 location")
pause
)
(setq p1 (getstring "\nBlock2 number: "))

 

(COMMAND "INSERT"  "C:\\MYFOLDER\\MYDRAWING.DWG")

 

;Explanation - Autolisp treats backslashes ("\") as control characters in a text string - that is why we need 2 at each subfolder division)

 

 

(SETQ sc (GETVAR "dimscale"))
(GETPOINT "Block2 location")
pause
)
)

 

P.S. would really appreciate explanation not just solution, want to understand this thing.

Thank you in advance.


 

Message 3 of 6
Kent1Cooper
in reply to: tmccar


@tmccar wrote:

 

....

(COMMAND "INSERT"  "C:\\MYFOLDER\\MYDRAWING.DWG")

.... 

(SETQ sc (GETVAR "dimscale"))
(GETPOINT "Block2 location")
pause
)
)

 

....

... but without that ) at the end of the red line [the ) further down ends the (command) function], and it still needs the Scale option called for as originally, which can just use the sc variable already established earlier, rather than extracting it again:

 

....

(COMMAND "INSERT"  "C:\\MYFOLDER\\MYDRAWING.DWG"

"_scale" sc

(GETPOINT "Block2 location")
pause
)
)

 

 

Kent Cooper, AIA
Message 4 of 6
scot-65
in reply to: Anonymous

>> I cant manage to find a right function or the right way how to specifie the folder where to look for blocks.

 

If you do not have a support path declared to the particular "Block" folder, perhaps write some

code to define a "hard-path" prefix? The downside to this method is when folder location changes

you will have to update the code to match.

 

(setq %BlkPath1% "I:\\System\\Block\\")

(setq %BlkPath2% "I:\\System\\Block\\Plan_notes_Lib\\")

etc.

 

And:

(if (setq BlkName (getstring "Enter name of block: "))

 

Then:

(cond

 ((findfile (strcat (setq a (strcat %BlkPath1% BlkName)) ".dwg")) (GO_INSERT a))

 ((findfile (strcat (setq a (strcat %BlkPath2% BlkName)) ".dwg")) (GO_INSERT a))

 etc.

 (T (princ (strcat "\n" BlkName " not found. ")))

);cond

 

);if

 

Where:

(defun GO_INSERT ( a / )

 (insert a ...

)

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 5 of 6
ace_guru
in reply to: Anonymous

Howdy,

 

Have you thought about using the findfile command. When you use this command it'll search through all the folders that Autocad is aware of. So just make sure you put the server location of where all your blocks are in the Support File Search Path, through the options menu.

 

Example:

(setq bubbledwg (findfile "Item_Bubble.dwg"))

 

Hope that helps.

 

 

Message 6 of 6
Anonymous
in reply to: Anonymous

Thank you all, I will try out all the ways when I will have some time to experiment.

I tried using double"\\" when pointing out location, but I will try it again.

Also tried findfile, but I guess AutoCad did not have server location set up in the setings.

Thanks once again.

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