Getting name of autocad drawing.

Getting name of autocad drawing.

Anonymous
Not applicable
7,818 Views
3 Replies
Message 1 of 4

Getting name of autocad drawing.

Anonymous
Not applicable

Hello everyone,

 

i have developed a dll flile in vb.net. After loading dll file in autocad, i want to do following.

 

1. To get name of opened active autocad file in which i running my command in text box of opened form.

2. To save some information in that autocad drawing . And also to read/modify that infomation when required.

 

Kindly some help me to do above through vb.net.

 

Thanks & Regards

Amit

 

 

0 Likes
7,819 Views
3 Replies
Replies (3)
Message 2 of 4

hgasty1001
Advisor
Advisor

Hi,

 

You need to get the value of  DWGNAME variable in order to obtain the dwg name. But if the file has no name, it will return just "DrawingX", with X a number, so you may need to check if the file has been saved with the "DWGTITLED" system variable.

 

The code to retrieve a variable value is just: Application.GetSystemVariable("TheVariableNameHere")

The code to set a variable to a value is just: Application.SetSystemVariable("SomeVariableName", TheValue)

 

You can type F1 in AutoCAD to get the help system and read about variables.

 

Gaston Nunez

 

 

Message 3 of 4

BKSpurgeon
Collaborator
Collaborator

For those researching in the future, this is my method:

 

Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
string drawingName = Path.GetFileName(doc.Name);

the string drawingName does also come with the extension. you can remove it from the string if you wish, I suppose.

Message 4 of 4

_gile
Consultant
Consultant

Hi,

 

1. Assuming doc is the active document (Application.DocumentManager.MdiActiveDocument) and db the related database (doc.Database),

- if the drawing is unsaved:

doc.Name returns the incremented default drawing name (DrawingN.dwg)

db.Filename returns the template path

- if the drawing have been saved:

both doc.Name and db.Filename return the drawing path.

 

2. To store data in a drawing

For persisting data, you should store them in Xdata or in Xrecord contained in a Dictionary (extension dictionary or named dictionary)

For transient data, you can store them as instance members (typically fields) of the class where the command is defined (see this topic) or use the document.UserData property (see this topic).

 

Sorry but as you can see most examples are in C#. You can use some converter or, better IMO, if you just start learning VB, switch to C#.

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub