Jump to content

Using an SCR to INSERT a block and set attributes


fd9db62e

Recommended Posts

Is there a way to set attributes during the insert process via scr file?

 

I have found a lot of topics on the internet that are close to what I am looking for but not exactly.

 

Some places suggest ATTREQ set to 1 and ATTDIA set to 0, but that doesn't seem to work for me.

 

Any thoughts?

Link to comment
Share on other sites

For predefined block with say 3 attributes, something like this no cad at moment.

 

-insert block1 '(0 0) 1 0 A B C

-insert block1 '(10 10) 1 0 A D G

-insert block1 "20,20" 1 0 A G H

Link to comment
Share on other sites

That nearly works, I just needed to add in the Y scale factor (and no quotes around the insertion point) and it needs to be done as a list type of script (seperate lines). For the first part keeping it on one line is ok, but when you get to the attribute values, they have to be on separate lines, a script will accept a space as part of an input string so it just joins all the remaing parts of a line together, and then it hangs waiting for the second value. So for just one inserted block with 3 attributes it should read as follows.attdia=0

-insert
block1
20,20
1
1
0
A
G
H

And attdia=0

Link to comment
Share on other sites

Last week I learned that if the block is set to scale uniformly (y and z scales are linked to the x scale), then it won't ask for the y scale upon insertion. It is unlikely the OP will need to know that, but we use a mix of both, so it was a spanner in my works until recently.

Link to comment
Share on other sites

Thank you for the replies. I am still having issues though.

 

 

That nearly works, I just needed to add in the Y scale factor (and no quotes around the insertion point) and it needs to be done as a list type of script (seperate lines). For the first part keeping it on one line is ok, but when you get to the attribute values, they have to be on separate lines, a script will accept a space as part of an input string so it just joins all the remaing parts of a line together, and then it hangs waiting for the second value. So for just one inserted block with 3 attributes it should read as follows.attdia=0

-insert
block1
20,20
1
1
0
A
G
H

And attdia=0

 

This did help with the format I was using etc.

 

I still cannot make it work though. To see if it was an issue with the blocks I was using I have created a Test Block (TestBlock.dwg). The attached picture is the properties for the attribute. Maybe I am doing something wrong when I create the block and attributes?

 

Capture.jpg

 

Here is the base code I am trying:

 

ATTREQ 1
ATTDIA 0
-insert
"*C:\Users\DEFAULT\Desktop\TestBlock.dwg"
0,0
1
0
NEWVALUE

 

I have tried it with/without ATTREQ.

 

I have tried just putting a value in (NEWVALUE)

 

I have tried putting the Tag first (VALUE) (NEWVALUE)

 

I have tried putting the prompt first (VAL) (NEWVALUE)

 

I have tried putting in the old value (TAG) (NEWVALUE)

 

I also tried using A and Attribute prior to (NEWVALUE) trying to see if I needed to trigger it somehow...

 

No matter what I do I end up with the block being inserted and a "Unknown Command:" for the last line.

 

Thoughts?

 

Last week I learned that if the block is set to scale uniformly (y and z scales are linked to the x scale), then it won't ask for the y scale upon insertion. It is unlikely the OP will need to know that, but we use a mix of both, so it was a spanner in my works until recently.

 

At least for the test block I created this ended up being quite useful. (see above example code)

Link to comment
Share on other sites

This is probably not the issue, but I think the syntax for scripting system variables ought to be

ATTREQ
1 
ATTDIA
0

Have you tried inserting this block manually using the -insert command at the command line? Does that give you any clues?

 

What does you command line say when you run this script? An especially, what is the last thing is says after it breaks?

Edited by YZ
Link to comment
Share on other sites

This is probably not the issue, but I think the syntax for scripting system variables ought to be

ATTREQ
1 ATTDIA
0

 

Have you tried inserting this block manually using the -insert command at the command line? Does that give you any clues?

 

What does you command line say when you run this script? An especially, what is the last thing is says after it breaks?

 

Capture2.jpg

 

The syntax I have seems to work for the ATTREQ and ATTDIA.

 

The command line looks pretty much the same if I type each line manually. It doesn't "ask" for the attribute it just "ends" the command after putting in the rotation.

Link to comment
Share on other sites

The command line looks pretty much the same if I type each line manually. It doesn't "ask" for the attribute it just "ends" the command after putting in the rotation.

 

If that is the case then it probably has to do with your block definition. If you upload the testblock.dwg I'm happy to have a look. Or you can check for yourself, when you insert it it should prompt you for the attribute value.

 

Try inserting it in a new drawing that does not already have that block defined.

 

When creating blocks with attributes it is important to create the attributes before writing it to a block.

Link to comment
Share on other sites

The problem is that stray "1" that is being given to the command line after the rotation value, that message "unknown command" is the giveaway, the first thing I would check is to make make sure you don't have any spaces at the end of any lines in your script.

Could you post a copy of the block and your script file (you will have to change the extension from .scr to .txt or it won't be accepted

Link to comment
Share on other sites

Fd9db62e, since your script revert to command prompt after setting the angle and ATTREQ is set to 1, I would say that your block doesn't have any attributes. Can you upload it here?

Link to comment
Share on other sites

If that is the case then it probably has to do with your block definition. If you upload the testblock.dwg I'm happy to have a look. Or you can check for yourself, when you insert it it should prompt you for the attribute value.

 

Try inserting it in a new drawing that does not already have that block defined.

 

When creating blocks with attributes it is important to create the attributes before writing it to a block.

 

I will upload it.

 

It is possible that I am creating the block incorrectly - this is the first time I have been creating blocks with attributes. I have used other peoples before but never created my own. I followed the same process to create the "testblock" as I did with my actual blocks so if there is an issue it should be the same.

 

I have been creating a new drawing and running the scr.

 

Not sure about the * in the drive path leave out.

 

I have been unable to make it actually insert the block without including the *...

 

 

The problem is that stray "1" that is being given to the command line after the rotation value, that message "unknown command" is the giveaway, the first thing I would check is to make make sure you don't have any spaces at the end of any lines in your script.

Could you post a copy of the block and your script file (you will have to change the extension from .scr to .txt or it won't be accepted

 

I will upload the scr (as txt) along with the dwg. Sorry I guess I should have been clearer the '1' was just a placeholder for where I was trying (VALUE) (NEWVALUE) etc. It generates the "unknown command" no matter what I put there - not just the '1'.

 

Fd9db62e, since your script revert to command prompt after setting the angle and ATTREQ is set to 1, I would say that your block doesn't have any attributes. Can you upload it here?

 

I will upload it.

 

 

Thanks for your help all!

test.txt

TestBlock.dwg

Link to comment
Share on other sites

There is a funny little thing about directories in Autocad it stems from the fact that Autocad was probably developed on a Unix box 30 years ago you often have to reverse the slash / \ and sometimes use \\ and put directory names in quotes "q:\\\\server1\\worsk\\projects stuff" directories with a space in the name in a script will often stop as the space is detected as a end of input. I dont have problems and never use * will have another look at your directory name.

Link to comment
Share on other sites

There were a few issues with the drawing and the script:

 

  • The block is defined in the attached drawing, so when attempt to insert it will appears to redefine itself. Please extract it using WBLOCK command.
  • Missed to input the Y scale.
  • By placing the "*" character at the begining of block name (path) will insert it exploded, therefore attribute's value will no be requested.
  • The value for the attribute contains spaces, so must be enclosed in quotes.
  • You have set your attribute to Verify, so need an additional for input confirmation. You may disable this parameter since may be useful only when set the attributes manually on prompter.
  • There should be another line at bottom to allows the command to end.

 

ATTREQ 1
ATTDIA 0
-insert
"[color=red]*[/color]C:\Users\DEFAULT\Desktop\TestBlock.dwg"
0,0
1
[color=red]1[/color]
0
[color=red]"[/color](place holder)[color=red]"[/color]

[color=red];end of script[/color]

Link to comment
Share on other sites

There were a few issues with the drawing and the script:

 

  • The block is defined in the attached drawing, so when attempt to insert it will appears to redefine itself. Please extract it using WBLOCK command.
  • Missed to input the Y scale.
  • By placing the "*" character at the begining of block name (path) will insert it exploded, therefore attribute's value will no be requested.
  • The value for the attribute contains spaces, so must be enclosed in quotes.
  • You have set your attribute to Verify, so need an additional for input confirmation. You may disable this parameter since may be useful only when set the attributes manually on prompter.
  • There should be another line at bottom to allows the command to end.

 

ATTREQ 1
ATTDIA 0
-insert
"[color=red]*[/color]C:\Users\DEFAULT\Desktop\TestBlock.dwg"
0,0
1
[color=red]1[/color]
0
[color=red]"[/color](place holder)[color=red]"[/color]

[color=red];end of script[/color]

 

Thank you!

 

The WBLOCK was the main part I was missing. Prior to using the WBLOCK command it didn't ask for the y scale - post WBLOCK it does. The "*" character explanation makes sense and after using the WBLOCK command it inserts properly without it. I agree that turning verify off makes sense for insertion via cli.

 

Thank you all for your input! I appreciate the help.

Link to comment
Share on other sites

  • 9 years later...
On 12/7/2023 at 1:09 AM, BIGAL said:

Explain what your trying to do.

Thank you for responding Big Al. Please help me to write script. I need it to place blocks base point at specific x, y coordinates for thousands of blocks and then move them to 0,0.

 

Screenshot 2023-12-08 075059.png

Edited by Wan
Link to comment
Share on other sites

"I need it to place blocks base point at specific x, y coordinates" yes understand, the block name and points say as a csv file or an Excel, Bname,x,y.

 

So if doing manually you would use Bedit and move the block objects, based on a point in the objects now becoming 0,0. 

 

Need a dwg with at least 3 blocks and details of point X,Y to now become 0,0 by moving block.

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...