I'm having trouble with the method "getsubentitycolor". It throws an exception if a color has not been assigned to the subentity (has color index 257). I'm sorting through all the faces of a brep looking for faces with specific colors and can catch the exceptions but catching all the exceptions seems to be consuming a lot of time. Is there any way to avoid the function throwing an exception? My code is as follows:
'searches solid for all faces with color then sends these out to sense unit faces
Private Sub FindSolidFaces(ByVal searchColor As acDefaultColors)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim solColorFaces As New List(Of brFace)
Dim solid As Solid3d = TryCast(trans.GetObject(mMwallSolid.SolidId, OpenMode.ForRead), Solid3d)
Using solidBrep As New Brep(solid)
'cycle through each face of the solid looking for color
For Each Face In solidBrep.Faces
Dim faceId As SubentityId = Face.SubentityPath.SubentId
Dim fceColor As New Color
Try
'this method throws an exception if a non-color is returned which
'will happen for each face that has a color "byEntity"
fceColor = solid.GetSubentityColor(faceId)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
End Try
If fceColor.ColorIndex = searchColor Then
'record the face
solColorFaces.Add(Face)
End If
Next
'send the units out to be analyzed
SenseUnitFaces(trans, checkedUnits, solidBrep, solColorFaces)
End Using 'solidBrep
trans.Commit()
End Using 'trans
End Sub
Hi
I was testing couple of things but I found no way to workaround that behavior.
Sorry for the bad news.
Regards,
Philippe.
I'm encountering an earlier error. Does this line work for you?
Dim faceId As SubentityId = Face.SubentityPath.SubentId
It throws an exception on my 2014 and 2015 setups. Are you using a different version?
****. That's a bit disconcerting. I can't get by that line without a Autodesk.AutoCAD.BoundaryRepresentation.Exception being thrown. And, I've tried it on both a 32 and 64 bit setup.
I actually have AutoCAD Mechanical, but I'm running it as Vanilla.
Am I the only one having trouble with that Method?
What kind of object are you passing in? I have had trouble with these functions depending on if I'm passing a solid extruded from polylines, vs. a simple box.
@tcuneio wrote:I'm having trouble with the method "getsubentitycolor". It throws an exception if a color has not been assigned to the subentity (has color index 257). I'm sorting through all the faces of a brep looking for faces with specific colors and can catch the exceptions but catching all the exceptions seems to be consuming a lot of time. Is there any way to avoid the function throwing an exception? My code is as follows:
'searches solid for all faces with color then sends these out to sense unit faces
Private Sub FindSolidFaces(ByVal searchColor As acDefaultColors)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.DatabaseUsing trans As Transaction = db.TransactionManager.StartTransaction
Dim solColorFaces As New List(Of brFace)
Dim solid As Solid3d = TryCast(trans.GetObject(mMwallSolid.SolidId, OpenMode.ForRead), Solid3d)
Using solidBrep As New Brep(solid)'cycle through each face of the solid looking for color
For Each Face In solidBrep.Faces
Dim faceId As SubentityId = Face.SubentityPath.SubentId
Dim fceColor As New Color
Try
'this method throws an exception if a non-color is returned which
'will happen for each face that has a color "byEntity"
fceColor = solid.GetSubentityColor(faceId)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
End Try
If fceColor.ColorIndex = searchColor Then'record the face
solColorFaces.Add(Face)End If
Next'send the units out to be analyzed
SenseUnitFaces(trans, checkedUnits, solidBrep, solColorFaces)
End Using 'solidBrep
trans.Commit()
End Using 'trans
End Sub
Catching exceptions is the very reason for a try block... Off the top of my head I'm thinking that there is a real possibility that it isn't the try block catching the exceptions that is causing your performance hit so much as the If block that follows it (in which you add it to your processing collection... The fceColor var may be set to anything from the previous run, or even be empty of values...
Try moving the If block inside the Try block and see if that helps you (it may also be a good idea to ensure that the fceColor var is of type ColorIndex before testing for the match against the searchColor).
Just a thought,
Gary
The "if" block seems to have been consuming resources as you say. I've written around it and no longer have the performance problem and the "try" is doing it's job so I'm happy again. Thanks for pointing out this issue!