"INSERT" command sequence

"INSERT" command sequence

john.uhden
Mentor Mentor
1,961 Views
12 Replies
Message 1 of 13

"INSERT" command sequence

john.uhden
Mentor
Mentor

I am writing the code for a solution to a current topic.

It involves inserting a block with two attributes, but I really don't know the block.

It might allow varied X and Y scales, and it might not.

Plus the block may exist as a dwg in the search path, but not yet defined in the current drawing.

How do you know how many pauses to provide before supplyling the two attribute values?

 

(vl-cmdf "_.INSERT" block_name pause pause pause att1 att2)  ???

(vl-cmdf "_.INSERT" block_name pause pause pause pause att1 att2)  ???

 

Or is there a better way to insert?

John F. Uhden

0 Likes
Accepted solutions (1)
1,962 Views
12 Replies
Replies (12)
Message 2 of 13

R0m3r014
Contributor
Contributor

@john.uhden wrote:

I am writing the code for a solution to a current topic.

It involves inserting a block with two attributes, but I really don't know the block.

It might allow varied X and Y scales, and it might not.

Plus the block may exist as a dwg in the search path, but not yet defined in the current drawing.

How do you know how many pauses to provide before supplyling the two attribute values?

 

(vl-cmdf "_.INSERT" block_name pause pause pause att1 att2)  ???

(vl-cmdf "_.INSERT" block_name pause pause pause pause att1 att2)  ???

 

Or is there a better way to insert?



Hi.

Maybe this code can help you.

 

(defun c:rei ( / blknm sclx scly pt)
	(setvar "cmdecho" 0)
	(setq blknm (getstring " Name block multiple insert "))
	(if (= (setq sclx (getreal "Scale in x  <1> ")) nil) (setq sclx 1))
	(if (= (setq scly (getreal "Scale in y <1> ")) nil) (setq scly 1))
	(while
		(setq pt (getpoint "\nLocalitation and angle:"))
        (command "insert" blknm pt sclx scly pause)
	)
	(princ)
);end

 

0 Likes
Message 3 of 13

pbejse
Mentor
Mentor
Accepted solution

@john.uhden wrote:

 

...How do you know how many pauses to provide before supplyling the two attribute values?

 


If you are going to stick to native insert command, and there are an unknown number of prompts (scale/attributes) what I would do is set ATTREQ to 0 and accept all the default values, pausing only for the basepoint . and input the attribute values after the fact.

 

Something like this.

 

 

(command "_.insert" bname pause)
(while (> (getvar "CMDACTIVE") 0)
      (command "")
      )

(setq Attributetobeaddedlater (entlast))

As for the block file name. Not sure though. but I think if you supply the full path for the blockname and the block exists in the current drawing, you will get the the current instances of that block.

 

 

I know that is the case when I use vlax-invoke 'Insertblock

 

HTH

 

Message 4 of 13

john.uhden
Mentor
Mentor

ATTREQ is an interesting idea.  Then post-process the insertion.

 

OR,

 

I think I found some old code of mine where I used entmake, as in...

entmake the "INSERT"

entmake the "ATTRIBs"

entmake the "SEQEND"

 

The 2002 help gave me no clues on handling attributes within the vla-insert method.

Guess I'll have to skin my knees trying these out.

Sorta dumb doing all this just to help the needy, but at least we might all learn something from it.

John F. Uhden

0 Likes
Message 5 of 13

Ranjit_Singh
Advisor
Advisor

@john.uhden wrote:

.............

It might allow varied X and Y scales, and it might not.

Plus the block may exist as a dwg in the search path, but not yet defined in the current drawing.

..................


Checking for block definition properties will allow you to identify if non-uniform scaling is allowed. Accordingly you can adjust the pauses for prompts. I am not sure I understand the second part correctly. I assume you mean a dwg file is already attached and a block cannot be defined with the same name? If so, make a predicate function to identify if such a drawing exists. In this case you do not need to test if the block allows non-uniform scaling, since the block isn't defined yet.

(defun somefunc-scallowed (blockname / bl); block scaling allowed
(and (setq bl (vl-catch-all-apply 'vla-item (list (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blockname)))
(null (vl-catch-all-error-p bl))
(if (zerop (vla-get-blockscaling bl)) T)))
0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

.....

It might allow varied X and Y scales, and it might not.

Plus the block may exist as a dwg in the search path, but not yet defined in the current drawing.

....


If it will at least always be Inserted  at uniform X & Y scales in the circumstances you're working in, you don't need to know whether it's defined  for uniform scaling or not, if you give it the Scale option in the Insert command, before the insertion-point pause:

 

.... "_.insert" block_name "_scale" pause pause ....

 

The first pause is for the scale factor, the second for the insertion point.  That also has the advantage that if it's a scale other than 1, you can see it at that scale  as you drag it around to the desired insertion point.  But if you need to preserve the possibility of different  scales, that approach won't do.

 

If it's in a Support File Search Path location, then Insert will find it if it's not already in the current drawing, so you don't have to worry about that part.  The "worry" could be if it might already be a Block in the current drawing, but you want to update its definition to match the external drawing if that may differ.

Kent Cooper, AIA
0 Likes
Message 7 of 13

john.uhden
Mentor
Mentor

Thanks, Ranjit.  I had not known about the blockscaling property.

I will write the code so that the block definition must already reside in the drawing, naturally prompt if not.  That makes the code a lot easier for me and friendlier to the needy one who can pick the insertion point, rotation and scale(s) before I provide the attribute values.

 

Out of curiosity, I wonder if you can entmake or vla-add attributes to a block insertion whose definition includes no attdefs.

John F. Uhden

0 Likes
Message 8 of 13

Ranjit_Singh
Advisor
Advisor

I thought we dealt with something similar here

0 Likes
Message 9 of 13

john.uhden
Mentor
Mentor

Bummer.  I found out that 2002 does not include a blockscaling property.

I'll have to get a copy of @Anonymous's block to see how it behaves.

Either that or I make an assumption, and if it doesn't work for him, then I add/subtract a pause.

 

OR, I follow PBGV's suggestion of turning off ATTREQ.  Maybe I'll try that.

John F. Uhden

0 Likes
Message 10 of 13

john.uhden
Mentor
Mentor

Turning off ATTREQ was the key to success.  Kudos to PBGV.

See the finished product here

John F. Uhden

0 Likes
Message 11 of 13

john.uhden
Mentor
Mentor

Turning off ATTREQ was the easiest way.

Kudos to PBGV.

 

 

John F. Uhden

0 Likes
Message 12 of 13

pbejse
Mentor
Mentor

@john.uhden wrote:

Turning off ATTREQ was the easiest way.

Kudos to PBGV.

 


Smiley LOL Has a nice ring to it though.

0 Likes
Message 13 of 13

john.uhden
Mentor
Mentor

Yes, I like it too.  They are very cute little critters.

 

BTW, I finally finished the project for @Anonymous under his "making life easier" topic

John F. Uhden

0 Likes