FInd the position of a drawing using a script

FInd the position of a drawing using a script

Anonymous
Not applicable
1,021 Views
6 Replies
Message 1 of 7

FInd the position of a drawing using a script

Anonymous
Not applicable

Forgive my ignorance. I'm a web developer tasked with integrating an app with AutoCAD and I have no experience with the software or CAD files in general.

 

I have hooked it up to A360 and the Forge APIs and now I'm looking to modify drawings using scripts uploaded to the Design Automation API. What I need to do is add part numbers and some other data generated by the app to the drawings. I have the following script I've managed to get working which is a very basic version of what I need to achieve.

 

; Add a label to a drawing
-mtext 0,300 400,310 App data
Tag No: P1234567
Created: 29/09/16

 

; Define Attribute
-attdef
i

 

P1234567
tag
-
0,200
10
0
; end

 

This script adds an MTEXT and ATTDEF to a drawing with a bit of basic data. What I want to do is position the labels at the bottom right of the drawing.

 

Is it possible to get the position of the drawing from somewhere so the script can figure out where the bottom right is? Ideally it needs to work no matter where the creator has positioned the drawing.

 

Bonus points: I'd also like to put this data into the drawing metadata somehow, would this be beneficial and how would be the best way to achieve this?

 

Thanks in advance.

0 Likes
1,022 Views
6 Replies
Replies (6)
Message 2 of 7

Ranjit_Singh
Advisor
Advisor

Ideally it needs to work no matter where the creator has positioned the drawing... makes me believe that the drawing is sitting in modelspace. In that case, does that drawing has some kind of enclosing block? You can extract the bottom right of the block.

If drawings are in layout tabs then the following should give you the bottom right of the layout

 

(list (car (getvar 'limmax)) (cadr (getvar 'limmin)))

Metadata can be attached in several ways. Using xrecord maybe best since then you can add it to the namedobjdict so it resides in the drawing. On the other hand, if you use xdata and attach it to a entity then the entity might get deleted at some point and you loose the xdata.

 

Message 3 of 7

Anonymous
Not applicable

makes me believe that the drawing is sitting in modelspace

 

I think you're on to something there, the client I'm building this for refers to the drawings as blocks. I have been messing with simple geometric shapes I've made to test this with, as he's not yet sent me his default blocks.

 

If I understand you correctly you draw your shapes then group all these into a block which makes it behave as one 'thing'. Once it's a block we can then use the method you suggested to place the label at the bottom right.

 

As for XRECORD, am I right that by using this command I could add data to the metadata and have it also display on the block? If so that sounds like what I want to use.

 

Thanks for your help, it's a bit dizzying trying to learn all this from scratch.

0 Likes
Message 4 of 7

Ranjit_Singh
Advisor
Advisor

I don't know the structure of your drawing. But yes if those drawings are blocks it might be possible to extract the bottom right.

XRECORD is not a command. I am completely confused by your last statement. If by metadata you mean information that you can retrieve by right-clicking a dwg file then that is operating system specific and there maybe 3rd party programs to add/edit such information. display on the block? Anything in the dwg file itself will need to be added by AutoCAD entities (use autoLISP or not is your personal choice). I don't think you can bring in information from metadata (if metadata is what I explained above).

 

You may have to provide more information on this forum as far as your ultimate goals. For more understanding on blocks see here and for Xrecord see here

0 Likes
Message 5 of 7

Anonymous
Not applicable

Sorry, didn't mean to confuse you.

 

I'm still getting to grips with the terminology of AutoCAD, I was thinking in terms of .scr files and thought XRECORD was a command like -MTEXT.

 

As for the metadata I'm aware they are separate I misinterpreted your comment about XRECORD. I'm going to forget about metadata for now and focus on getting the text into the right place on the blocks.

 

Thanks for the links, and you're time, they've helped.

 

 

0 Likes
Message 6 of 7

Ranjit_Singh
Advisor
Advisor

You are welcome. If you run into issues then post a sample drawing and clearly identify what you need to accomplish. You can usually get lot of relevant help if you post a sample dwg. Good luck.

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@Ranjit_Singh wrote:

....

If drawings are in layout tabs then the following should give you the bottom right of the layout

 

(list (car (getvar 'limmax)) (cadr (getvar 'limmin)))

.... 


If it's in either Model Space or Paper Space, and if nothing is drawn outboard of the right or bottom edges of the "nominal" [desired, effective, whatever] drawing area that you want to know the bottom right corner of, then you don't need to concern yourself with the limits, or things to be defined into Blocks, etc.  AutoCAD knows the extents of the drawing, and can calculate the bottom right corner from them.  Do a ZOOM ALL or ZOOM EXTENTS first [because what it knows about the extents can be affected by Erasing or Moving things, but is reset by Zoom A or Zoom E], and then this is the bottom right corner:

 

(list (car (getvar 'extmax)) (cadr (getvar 'extmin)))

Kent Cooper, AIA
0 Likes