View Full Version : updating a custom property bag value
adam.kalajzich
2008-10-01, 05:22 AM
Hello,
I was wondering if any one knows how to update a custom property bag value of a sheet with the begin_save procedure.
Im trying to populate a CPB called XREF with the xrefs of the current drawing.
Private Sub AcadDocument_BeginSave(ByVal Filename As String)
PopulateFields
End Sub
''' populate sheetset fields
Sub PopulateFields()
Dim i As Integer
Dim strXRef As String
Dim oSheetSetMgr As AcSmSheetSetMgr
Set oSheetSetMgr = New AcSmSheetSetMgr
Dim oSheetDb As AcSmDatabase
Set oSheetDb = oSheetSetMgr.GetDatabaseEnumerator().Next
LockDatabase oSheetDb
strXRef = ""
For i = 0 To ThisDrawing.Blocks.Count - 1 '' all blocks
'' is the item a acad xref
If ThisDrawing.Blocks.Item(i).IsXRef Then '' if it is
strXRef = strXRef + ThisDrawing.Blocks.Item(i).Name + ";"
End If
Next i
ThisDrawing.Utility.Prompt ("XRefs: " & strXRef & vbCrLf) ''' debug
'' apply the xref string, this works... sort of, but applys it to the sheetset, not sheet...
Dim cBag As AcSmCustomPropertyBag
Dim cBagVal As New AcSmCustomPropertyValue
Set cBag = oSheetDb.GetSheetSet().GetCustomPropertyBag
cBagVal.InitNew cBag
cBagVal.SetFlags CUSTOM_SHEET_PROP
cBagVal.SetValue strXRef
cBag.SetProperty "XREF", cBagVal
Set cBagVal = Nothing
UnlockDatabase oSheetDb
'' ThisDrawing.Utility.Prompt ("XREFS:" & strXRef & vbCrLf)
'' put strXRef to the XRef CPB.
''LockDatabase oSheetDb
''SetCustomProperty oSheetDb, "XREF", strXRef, False
''UnlockDatabase oSheetDb
End Sub
All documentation that I have found details setting and creating CPB and values, but nowhere can I find documentation about updating CPB values.
RobertB
2008-10-01, 04:13 PM
Look at the SetCustomProperty procedure in the rrbISheet class in my AU 2007 CP215-2 handout.
adam.kalajzich
2009-03-09, 06:22 AM
Hello again,
been a while since i have worked on this. I am still working on updating the custom property bag updating. I am using the SetCustomProperty routine as shown here: which is part of the AU 2007 CP215-2 handout.
'' Set/Create a Sheet Set Property
Private Sub SetCustomProperty(oSheetDb As AcSmDatabase, strName As String, strValue As Variant, Optional bSheetSetFlag As Boolean = True)
'' Create a Reference to the Custom Property Bag
Dim cBag As AcSmCustomPropertyBag
Set cBag = oSheetDb.GetSheetSet().GetCustomPropertyBag
'' Create a Reference to a Custom Property Value
Dim cBagVal As New AcSmCustomPropertyValue
cBagVal.InitNew oSheetDb.GetSheetSet() '' cBag
'' Set the Flag for Sheet Set or Sheet Property
If bSheetSetFlag = True Then
cBagVal.SetFlags CUSTOM_SHEETSET_PROP
Else
cBagVal.SetFlags CUSTOM_SHEET_PROP
End If
'' Set the value for the Bag
cBagVal.SetValue strValue
'' Create the property
cBag.SetProperty strName, cBagVal
'' Cleat variable
Set cBagVal = Nothing
End Sub
Now I am iterating though the sheetset series untill i find the drawing i want. Thus the custom properties that I want to alter, which is the revision history. Copy n-1 revision to n for each property listed below (hard coded) and check to see if new property = old property, but it doesn't. Therefore the setcustomproperty is not working...
the routine is below. If any one is able to assiste me with what I am doing wrong please let me know?
Sub Update_revisions()
Dim Sheetset As New Sheetset
Dim ssMgr As New AcSmSheetSetMgr
Dim dbIter As IAcSmEnumDatabase
Dim db As IAcSmDatabase
Set dbIter = ssMgr.GetDatabaseEnumerator
Set db = dbIter.Next
LockDatabase db
Do While Not db Is Nothing
On Error Resume Next
Dim iter As IAcSmEnumPersist
Dim Item As IAcSmPersist
Dim sheet As IAcSmSheet
Dim sheet2 As IAcSmSheet2
Dim i As Integer
Dim strDwg As String
Dim dwg As String
Dim strRev As String
Dim strDate As String
Dim strDesc As String
Dim strCheck As String
Dim strTemp As String
strDwg = InputBox("No: ", "Drawing Number", "Drawing number")
strRev = InputBox("Rev: ", "Revision Number", "Revision number")
strDate = InputBox("Date: ", "Revision Date", "xx/xx/xxxx")
strDesc = InputBox("Desc: ", "Description", "Enter description here")
strCheck = InputBox("Check: ", "Checked by", "Name of person")
Set iter = db.GetEnumerator
Set Item = iter.Next
Do While Not Item Is Nothing
Set sheet = Item
If Item.GetTypeName = "AcSmSheet" Then
dwg = sheet.GetNumber
If dwg = strDwg Then
ThisDrawing.Utility.Prompt ("Drawing found: " & dwg & " = " & strDwg & vbCrLf)
Dim myProps As AcSmCustomPropertyBag
Set myProps = sheet.GetCustomPropertyBag
Dim myProp As IAcSmCustomPropertyValue
For i = 7 To 2 Step -1
Set myProp = myProps.GetProperty("REVNO0" & CStr(i - 1))
strTemp = myProp.GetValue
SetCustomProperty db, "REVNO" & CStr(i), strTemp, False
''debuging strTemp should = same
Set myProp = myProps.GetProperty("REVNO0" & CStr(i))
ThisDrawing.Utility.Prompt (strTemp & " = " & myProp.GetValue & vbCrLf)
Set myProp = myProps.GetProperty("REVDATE0" & CStr(i - 1))
strTemp = myProp.GetValue
SetCustomProperty db, "REVDATE0" & CStr(i), strTemp, False
'debuging strTemp should = same
Set myProp = myProps.GetProperty("REVDATE0" & CStr(i))
ThisDrawing.Utility.Prompt (strTemp & " = " & myProp.GetValue & vbCrLf)
Set myProp = myProps.GetProperty("REVDESC0" & CStr(i - 1))
strTemp = myProp.GetValue
SetCustomProperty db, "REVDESC0" & CStr(i), strTemp, False
'debuging strTemp should = same
Set myProp = myProps.GetProperty("REVDESC0" & CStr(i))
ThisDrawing.Utility.Prompt (strTemp & " = " & myProp.GetValue & vbCrLf)
Set myProp = myProps.GetProperty("REVCHECK0" & CStr(i - 1))
strTemp = myProp.GetValue
SetCustomProperty db, "REVCHECK0" & CStr(i), strTemp, False
'debuging strTemp should = same
Set myProp = myProps.GetProperty("REVCHECK0" & CStr(i))
ThisDrawing.Utility.Prompt (strTemp & " = " & myProp.GetValue & vbCrLf)
If i = 1 Then
strTemp = sheet2.GetRevisionNumber
SetCustomProperty db, "REVNO" & CStr(i), strTemp, False
strTemp = sheet2.GetRevisionDate
SetCustomProperty db, "REVDATE0" & CStr(i), strTemp, False
strTemp = sheet2.GetIssuePurpose
SetCustomProperty db, "REVDESC0" & CStr(i), strTemp, False
Set myProp = myProps.GetProperty("CHECKEDBY")
strTemp = myProp.GetValue
SetCustomProperty db, "REVCHECK0" & CStr(i), strTemp, False
End If
Next i
sheet2.SetRevisionNumber strRev
sheet2.SetRevisionDate strDate
sheet2.SetIssuePurpose strDesc
SetCustomProperty db, "CHECKEDBY", strCheck, False
End If
End If
Set Item = iter.Next
Loop
Set db = Nothing
Set db = dbIter.Next
Loop
Set dbIter = Nothing
Set ssMgr = Nothing
UnlockDatabase db
End Sub
Again, thanks in advance for any help you may offer. I appologise for the ugliness of my code. I am sure the answer is easy, but I cannot see it.
adam.kalajzich
2009-03-16, 06:04 AM
Ok,
Seems like i have realy stumped people here. Trying a different approch then... how do i destroy or delete a customproperty[bag|value|item]?
Cause if i can destroy it / delete it, then I should be able to re-create it with the correct value, using the CP215-7 handout function. Or even better, using the same function to check if it already exists and delete before recreating it.
Thanks again for any help.
RobertB
2009-03-16, 02:15 PM
There is no need to destroy the custom property. There is the SetProperty method on the CustomPropertyBag object. The code you posted isn't useful since you didn't post the SetCustomProperty procedure.
Also, I think you are locking the database way too early. As I mention in the handout, lock the db only when you need. Early/extensive locking will lead to performance issues.
adam.kalajzich
2009-03-16, 10:24 PM
Hello Robert,
Thanks for the reply.
I belive i did show the SetCustomProperty, it is the first chunk of code. it is 99% verbatim of the CP215-2 handout. It is the first chunk of code in post number 3.
As too the locking and unlocking the db, would you recommend that I place it within the loop or just outside of the loop?
RobertB
2009-03-17, 12:25 AM
I belive i did show the SetCustomProperty, it is the first chunk of code. it is 99% verbatim of the CP215-2 handout. It is the first chunk of code in post number 3. Oops, my mistake.
The problem with that code is that you are trying to use the same code to modify the custom properties of both a SheetSet object and a Sheet object. You cannot use the SheetSet object to modify a sheet's custom properties.
As too the locking and unlocking the db, would you recommend that I place it within the loop or just outside of the loop?Inside the loop, but only when you modify the value. The same as the handout's SetCustomProperty procedure on the rrbiSheet class.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.