Jump to content

Recommended Posts

Posted

Before I start I would just like to say I am completely new to VBA but once you hear about the things you can achieve with it I can't wait to start.

 

The outcome of my first vba code is to automatically produce a drawing register within excel.

 

Using Autocad VBA I have managed so far to open excel and produce a standard issue sheet in code

 

In AutoCAD within our drawing files we use Custom Fields in the Drawing Properties (Custom) ToolBar.

 

These custom fields namely:

 

PROJECT1

PROJECT2

PROJECT3

JOB NO

 

Put simply : what code would I use to simply place PROJECT1 field into excel field B11.

Posted

I don't use VBA but I think the custom fields are stored as dictionary objects. So there you should start searching for.

Posted

This is SummaryInfo object - property of Document object. It has AddCustomInfo, GetCustomByIndex, GetCustomByKey, NumCustomInfo, RemoveCustomByIndex, RemoveCustomByKey, SetCustomByIndex, SetCustomByKey methods to manage custom properties. Access via

 

Dim cPrp = As AcadObject

 

Set cPrp = ThisDrawing.SummaryInfo

Posted

Function to get custom property by key in AutoLISP syntax:

 

(defun GetInfo(Key / sInf cPrp pVal)
 (vl-load-com)
 (setq sInf(vla-get-SummaryInfo
      (vla-get-ActiveDocument
        (vlax-get-acad-object))))
 (if(vl-catch-all-error-p
       (vl-catch-all-apply 'vla-GetCustomByKey
	   (list sInf Key 'pVal)))
     (princ(strcat "\n*** ERROR. Key '" Key "' not fouund! "))
     (princ(strcat "\n" Key " = " pVal))
   ); end if
 (princ)
 ); end of GetInfo

 

Testing:

 

Command: (GetInfo "Project Name")
Project Name = Test Name

 

Command: (GetInfo "Drawing name")
*** ERROR. Key 'Drawing name' not fouund!

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