How to use VBA to create a custom property for a sheet in a sheet set

How to use VBA to create a custom property for a sheet in a sheet set

Anonymous
Not applicable
1,006 Views
2 Replies
Message 1 of 3

How to use VBA to create a custom property for a sheet in a sheet set

Anonymous
Not applicable
I'm new to VBA for AutoCAD, and I'm trying to create a custom property for a sheet in a sheet set. In the example I find the following code:

Dim cBag As IAcSmCustomPropertyBag
Dim cBagVal As New AcSmCustomPropertyValue

Set cBag = sheetdb.GetSheetSet().GetCustomPropertyBag

cBagVal.InitNew cBag

cBagVal.SetFlags CUSTOM_SHEETSET_PROP
cBagVal.SetValue CStr(sheetCount)

cBag.SetProperty "Total Sheets", cBagVal

Set cBagVal = Nothing

But the owner of the custom property created here is the Sheet Set, not the Sheet. I need a custom property for each sheet, how can I do this? Can anybody help? Thanks.

Regards,
HM
0 Likes
1,007 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
I don't have time to explain it all, but here are some links that will help
http://jtbworld.blogspot.com/2006/04/sheet-set-manager-code-snippets.html
http://www.augi.com/education/auhandouts/2005/CP15-1.pdf

Sheetsets require unlocking to modify the child objects and locking the sheetset thereafter to be able to use it.

It took me a while to get it, since the help files aren't very much help.

If it serves your purpose, you may want to look into is setting the custom properties for the dwg file, rather then the sheetset. It is much easier. You can use these custom properties with text fields but cannot use in fields for other files. Here is some functions for that.

Private Function custFldAry() As String
'makes a comma delimted string of existing
'custom properties and values
On Error GoTo errCaseH
Dim docInfo As AcadSummaryInfo
Set docInfo = ThisDrawing.SummaryInfo
Dim fName As String
Dim fVal As String
Dim i As Integer
For i = 0 To (docInfo.NumCustomInfo - 1)
docInfo.GetCustomByIndex i, fName, fVal
fName = Trim(fName)
fVal = "," & Trim(fVal)
custFldAry = custFldAry & "," & Trim(fName) & fVal
Next i
If Trim(Replace(custFldAry, ",", "")) = "" Then custFldAry = ""
Set docInfo = Nothing
Exit Function
errCaseH:
Set docInfo = Nothing
custFldAry = ""
End Function

Private Function mkFldCode(inputStr) As String
'makes a field code for a custom property
mkFldCode = "%<\AcVar CustomDP." & inputStr & ">%"
End Function

Private Function changeFld(docName As AcadDocument, _
fldName As String, newVal As String) As Boolean
'changes a custom property value, or creates custom prop
'and assigns a value
On Error GoTo errCaseG
changeFld = True
Dim custProps As AcadSummaryInfo
Set custProps = docName.SummaryInfo
If InStr(custFldAry, fldName) < 1 Then GoTo createIt
custProps.SetCustomByKey fldName, newVal
Set custProps = Nothing
Exit Function
createIt:
custProps.AddCustomInfo fldName, newVal
Set custProps = Nothing
Exit Function
errCaseG:
changeFld = False
Set custProps = Nothing
End Function
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thank you very muck.
0 Likes