Improved code for inserting blocks into a drawing

Improved code for inserting blocks into a drawing

AlexBern44
Advocate Advocate
583 Views
4 Replies
Message 1 of 5

Improved code for inserting blocks into a drawing

AlexBern44
Advocate
Advocate

I would like to improve the code that is used to insert blocks into the drawing:

(command "_.insert" "C:\\Desktop\\\\Test" pause "5" "" "")

 

I specified a factor of 5 for the insertion scale.

 

The problem is that the block size is not displayed correctly at the moment when the block is already in the drawing and  need to specify the insertion point. This only applies to visibility.
Once the insertion point is indicated and the block has occupied its place in the drawing then its size becomes correct.

 

I have tested if in the continuation of this command, I specify the scale again, the size becomes correct.
I am referring to this request that appears after the top code:

Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:

 

My question is whether these two codes can be combined into one.

I'll give an example below, it's just to illustrate the idea and of course it can't work. This code could be something like this:

(command "_.insert" "C:\\Desktop\\\Test" pause "" "" "" "_Scale" "5")

 

Thanks in advance,
Alex

0 Likes
Accepted solutions (1)
584 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

Possibly like this

 

(defun c:Test ()
  (if (not (tblsearch "block" "Rectangle"))
    (progn (command "_.insert" "c:/Users/Desktop/_Download/Rectangle.dwg") (command)))
  (command "_.insert" "Rectangle" "_s" 5 "_r" 0 pause)
  (princ)
  )
Message 3 of 5

AlexBern44
Advocate
Advocate

Thank you for this lisp.

But it's not quite what I wanted.
I need code that consists of one line.
I found a solution. This code works perfectly and answers my original request:

(vl-cmdf "_.-insert" " C:\\Desktop\\Tests" "_scale" 5 pause "")

In this code, I would like to add a function to explode the block immediately after inserting it into the drawing.
I wrote such a code, but it doesn't work.

(vl-cmdf "_.-insert" " C:\\Desktop\\Tests" "_scale" 5 pause """_explode" (entlast))

Do you happen to know how to fix this?

I would appreciate your help.

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@AlexBern44 wrote:

....

I need code that consists of one line.

.... This code works perfectly and answers my original request:

(vl-cmdf "_.-insert" " C:\\Desktop\\Tests" "_scale" 5 pause "")

.... I would like to add a function to explode the block immediately after inserting it into the drawing.
I wrote such a code, but it doesn't work.

(vl-cmdf "_.-insert" " C:\\Desktop\\Tests" "_scale" 5 pause """_explode" (entlast))

....


[Why do you need it on one line?]

 

[I don't think it should be the problem, but most people would put a space between the "" and the "_explode".]

 

It's not quite clear to me from Help's description, but could it be that (vl-cmdf) wants to deal with only one command, the way (command-s) does?  Try using (command) instead, in which you can certainly include multiple commands like that.  Or try separate (vl-cmdf) functions:

(vl-cmdf "_.insert" "C:\\Desktop\\Tests" "_scale" 5 pause "") (vl-cmdf "_.explode" (entlast))

 

 

Kent Cooper, AIA
0 Likes
Message 5 of 5

AlexBern44
Advocate
Advocate

Your bottom version of me fit perfectly. Thanks to you, I learned new things.
I need this code to insert a block into a drawing via the command line.
I am developing a program with a library of ready-made elements. Communication with AutoCAD occurs through the command line.
The code is required for a special type of block that includes multiple blocks. It can be a series of trees or people, for example. After exploding the main block, the user can disperse them in the drawing.

0 Likes