Search code examples
autocadautocad-pluginautodesk-designautomation

AutoCAD script: Find drawing position


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.


Solution

  • If you would still like to do it in Modelspace, and you can control the drawings, it is possible to achieve this by finding the position of blocks with specific names.

    Example: http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/find-a-block-and-get-it-s-insertion-point/m-p/3309261#M302014