Getsubentitycolor

Getsubentitycolor

tcuneio
Enthusiast Enthusiast
1,545 Views
9 Replies
Message 1 of 10

Getsubentitycolor

tcuneio
Enthusiast
Enthusiast

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

0 Likes
1,546 Views
9 Replies
Replies (9)
Message 2 of 10

philippe.leefsma
Alumni
Alumni

Hi

 

I was testing couple of things but I found no way to workaround that behavior.

 

Sorry for the bad news.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 10

tcuneio
Enthusiast
Enthusiast

Thanks for looking into it.

0 Likes
Message 4 of 10

SEANT61
Advisor
Advisor

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?


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 5 of 10

tcuneio
Enthusiast
Enthusiast

This line works in my vanilla 2015 version.

0 Likes
Message 6 of 10

SEANT61
Advisor
Advisor

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


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 7 of 10

tcuneio
Enthusiast
Enthusiast

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.

0 Likes
Message 8 of 10

Gary_J_Orr
Collaborator
Collaborator

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


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

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager

aka (current and past user names)
GaryOrrMBI (MBI Companies 2014-Present), Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 9 of 10

tcuneio
Enthusiast
Enthusiast

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!

0 Likes
Message 10 of 10

Gary_J_Orr
Collaborator
Collaborator
Glad I could be of help...
If you can't find a way to be happy in your job then it's time for a new job, and we don't want that now do we?

*ReallyBigGrin*

-Gary
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager

aka (current and past user names)
GaryOrrMBI (MBI Companies 2014-Present), Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes