Hi, I'm working with ACA and vb.net, could anyone clarify the Object Browser info given below.
Public Shared Function GetClassification(ByVal entity As Autodesk.Aec.DatabaseServices.Entity, ByVal classificationDefinitionId As Autodesk.AutoCAD.DatabaseServices.ObjectId) As Autodesk.AutoCAD.DatabaseServices.ObjectId
Member of: Autodesk.Aec.DatabaseServices.ClassificationDefinition
Summary:
Get an entity's classification for a specific classification definition.
Parameters:
entity: The entity.
classificationDefinitionId: The classification definition.
Return Values:
Returns an entity's classification for a specific classification definition.
Exceptions:
Autodesk.AutoCAD.Runtime.Exception: Autodesk.AutoCAD.Runtime.Exception.
I think that what this is saying here is that I need to isolate an entity (which the classifcation is attached to - which is my case is a AecDbSpace. Then I need to add to this isolate the Object ID for the classfication that I'm want to read.
What I'm not sure about is if I have the AecDbSpace ObjectID, how do I turn this into an entity or are they in effect, the same kind of thing. Currently my code is not reading any classfications in the count property (spobj.Classifications.Count) when I just use a straight objectID - where there should be four classfications available on these AecDbSpace objects.
The mere fact that Intellisense gave me the option of writing spobj.Classifications suggests to me that MSExpress considers spobj to be an Entity - so maybe I have got this right - which then would mean that I'm using the wrong Entity to create a collection of classifications from.
Thanks in advance!
#Region "Namespaces"
Imports System
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.Aec.DatabaseServices
Imports Autodesk.Aec.PropertyData.DatabaseServices
Imports DBTransactionManager = Autodesk.AutoCAD.DatabaseServices.TransactionManager
Imports AcadDb = Autodesk.AutoCAD.DatabaseServices
Imports AecDb = Autodesk.Aec.DatabaseServices
Imports AecPropDb = Autodesk.Aec.PropertyData.DatabaseServices
Imports ObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId
Imports ObjectIdCollection = Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection
Imports AecDbSrvcs = Autodesk.Aec.DatabaseServices
Imports ArchDbSrvcs = Autodesk.Aec.Arch.DatabaseServices
#End Region
Public Class Renumber_Blocks
#Region "Command_Renumber"
' <summary>
' Command implementation for SetPropertyDataByName.
' </summary>
<Autodesk.AutoCAD.Runtime.CommandMethod("AecPropertySampleMgd", "koe", Autodesk.AutoCAD.Runtime.CommandFlags.Modal)> _
Public Sub Command_SetPropertyDataByName()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim psetname As String = "Block_properties"
Dim pname As String = "Block_ID"
Dim NewValue As Integer = 0
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tm As AcadDb.TransactionManager = db.TransactionManager
Dim dbobj As AcadDb.DBObject
Dim trans As Transaction = tm.StartTransaction()
Dim bt As BlockTable = tm.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord = tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead, False)
Dim id As ObjectId
For Each id In btr
If id.ObjectClass.Name = "AecDbSpace" Then
dbobj = tm.GetObject(id, OpenMode.ForRead, False, False)
Dim spobj As ArchDbSrvcs.Space = tm.GetObject(id, OpenMode.ForRead, False, False)
Dim c_classf As ClassificationCollection = spobj.Classifications
'Dim Clasf_Entity As Autodesk.Aec.DatabaseServices.Entity = CType(tm.GetObject(dbobj, OpenMode.ForRead, True), Autodesk.Aec.DatabaseServices.Entity)
'Dim target_clasf As Autodesk.Aec.DatabaseServices.ClassificationDefinition = ClassificationDefinition.GetClassification(Clasf_Entity)
'GetClassification(ByVal entity As Autodesk.Aec.DatabaseServices.Entity, ByVal classificationDefinitionId As Autodesk.AutoCAD.DatabaseServices.ObjectId) As Autodesk.AutoCAD.DatabaseServices.ObjectId
If c_classf.Count <> 0 Then
Dim classf_category As String = c_classf(0).ToString
End If
Dim spceStyle As ArchDbSrvcs.SpaceStyle = tm.GetObject(spobj.StyleId, OpenMode.ForRead, False, False)
If spceStyle.Name = "Block" Then
'Dim values As System.Collections.ArrayList = GetValueFromPropertySetByName(psetname, pname, dbobj)
'Dim value_unit As AecPropDb.PropertyValueUnitPair
'For Each value_unit In values
' Dim currentValue As Object = value_unit.Value
' If Not currentValue Is Nothing Then
' If (currentValue.GetType() Is GetType(Double)) Then
Dim trans2 As Transaction = tm.StartTransaction()
dbobj.UpgradeOpen()
Dim WasChanged As Boolean = SetValueFromPropertySetByName(psetname, pname, dbobj, NewValue)
If WasChanged Then
ed.WriteMessage(vbCrLf + "Succesfully changed value for objectId = " + id.ToString())
ed.WriteMessage(vbCrLf + " New Value = " + NewValue.ToString())
NewValue = NewValue + 1
Else
ed.WriteMessage(vbCrLf + "Failed to change value for objectId = " + id.ToString())
End If
trans2.Commit()
trans2.Dispose()
' End If
'End If
End If
End If
Next
'Next
trans.Commit()
trans.Dispose()
End Sub
#End Region
#Region "GetValueFromPropertySetByName"
' <summary>
' Returns the value (PropertyValueUnitPair) of a property by name on a given object.
' </summary>
' <param name="pname">The property name to find on the object.</param>
' <param name="dbobj">The object to find the property on. </param>
' <returns> An array of the values </returns>
Public Function GetValueFromPropertySetByName(ByVal psetname As String, ByVal pname As String, ByVal dbobj As AcadDb.DBObject) As ArrayList
Dim setIds As ObjectIdCollection = AecPropDb.PropertyDataServices.GetPropertySets(dbobj) 'this is almost like a count in that it is counting the number of psets attached to dbobj
Dim values As System.Collections.ArrayList = New System.Collections.ArrayList() 'this sets up the collector that is returned by the function
If setIds.Count = 0 Then
Return values
End If
'at this point, where setIds.count <> 0, then we know that we have property set attached
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tm As AcadDb.TransactionManager = db.TransactionManager
Dim psId As ObjectId
Dim local_psetName As String
'this is searching every property set looking for a single category - no need!! It may only cycle through 3 psets
For Each psId In setIds
'opens the propertyset found at psid in setid (where setid is the collection of psets on the dbobj) - so this is cycle one
Dim pset As AecPropDb.PropertySet = tm.GetObject(psId, OpenMode.ForRead, False, False) 'As AecPropDb.PropertySet
local_psetName = pset.PropertyIdToName(0)
Try
local_psetName = psetname 'this needs to true or else it goes to the catch
Dim psetdef_id As Integer
Try
'clever this - there is no cycling since pset is a collection and you can hunt down a name directly
'here it hunts down the pname
psetdef_id = pset.PropertyNameToId(pname)
'values is an arraylist since it holds any text or integer date - otherwise the function would have trouble returning a value
values.Add(pset.GetValueAndUnitAt(psetdef_id))
Catch e As Autodesk.AutoCAD.Runtime.Exception
' most likely eKeyNotfound.
End Try
Catch e As Autodesk.AutoCAD.Runtime.Exception
' most likely eKeyNotfound.
End Try
Next
Return values
End Function
#End Region
#Region "SetValueFromPropertySetByName"
' <summary>
' Sets the values (PropertyValueUnitPair) of a property by name on a given object.
' </summary>
' <param name="pname">The property name to find on the object.</param>
' <param name="dbobj">The object to set the property on. </param>
' <param name="value">The value to set. </param>
' <returns> true if succesful, or false otherwise. </returns>
Public Function SetValueFromPropertySetByName(ByVal psetname As String, ByVal pname As String, ByVal dbobj As AcadDb.DBObject, ByVal NewValue As Object) As Boolean
Dim findany As Boolean = False
Dim setIds As ObjectIdCollection = AecPropDb.PropertyDataServices.GetPropertySets(dbobj)
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tm As AcadDb.TransactionManager = db.TransactionManager
Dim trans As Transaction = tm.StartTransaction()
Dim psId As ObjectId
For Each psId In setIds 'setids is all property sets
Dim pset As AecPropDb.PropertySet = tm.GetObject(psId, OpenMode.ForWrite, False, False) ' As AecPropDb.PropertySet
If pset.PropertySetDefinitionName = psetname Then
Dim pid As Integer 'have to create this object to place the PropertyNameToId somewhere
pid = pset.PropertyNameToId(pname) 'propertynametoid gives the id for the psetdef
If (pset.IsWriteEnabled) Then
pset.SetAt(pid, NewValue) 'note the SetAt...this is vital where all factors are in place ie <pset> <pid> and <NewValue>
End If
findany = True
'esential findany changes the value of the function
End If
Next
trans.Commit()
trans.Dispose()
Return findany
End Function
#End Region
End Class