Jump to content

How to get active AutoCAD project path using VBA


santh

Recommended Posts

Hi

 

I need to get the path of the active project in AutoCAD using VBA. I have found autocad API (ace_getactiveproject) to find the path, but i dont know how to use it in VBA..

Is their any other way to get the path??

 

Thanks in advance

Link to comment
Share on other sites

The Developer Help (ActiveX and VBA Reference) has a good example. In the help file search for SetProjectFilePath Example.

Link to comment
Share on other sites

Thanks for ur input

 

i have one more query. I have created a new project in Autocad electrical. Is it possible to retive the Activeproject name using VBA?

 

thanks

Link to comment
Share on other sites

When is use this

currProjName = ThisDrawing.GetVariable("PROJECTNAME") statement it is returning empy string(currProjName ="" )

 

Instead of PROJECTNAME if I use "123"(My active project) am getting error "Error getting system variable"

help me out pls

 

thanks

Link to comment
Share on other sites

It appears that the example I referred you to had errors. :?

Try the revised example below, and see if this is helpful.

 

Sub Example_SetProjectFilePath()
   ' This example finds the current project file information, changes
   ' that information, and finally resets the information back to the
   ' original values.
   
   Dim preferences As AcadPreferences
   Set preferences = ThisDrawing.Application.preferences
   
   ' Get the current project file information
   Dim currProjPath As String
   Dim currProjName As Variant
   currProjName = ThisDrawing.GetVariable("PROJECTNAME")
   If currProjName <> "" Then
       currProjPath = preferences.Files.GetProjectFilePath(currProjName)

   End If
   If currProjPath = "" Then
       MsgBox "There is no current project file or path. ", , "SetProjectFilePath Example"
   Else
       MsgBox "The current project file path is: " & currProjPath, , "SetProjectFilePath Example"
       ' Set new project file information.
       ' Change drive/path as necessary to match your system
       Dim newProjPath As String
       newProjPath = "C:/AutoCAD/"
       
       preferences.Files.SetProjectFilePath currProjName, newProjPath
       MsgBox "The new project file path is: " & newProjPath, , "GetProjectFilePath Example"
       
       ' Reset the project file information
       preferences.Files.SetProjectFilePath currProjName, currProjPath
       MsgBox "The project file path has been reset to: " & currProjPath, , "GetProjectFilePath Example"
   End If
   
End Sub

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...