.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getsubentitycolor

9 REPLIES 9
Reply
Message 1 of 10
tcuneio
536 Views, 9 Replies

Getsubentitycolor

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

9 REPLIES 9
Message 2 of 10
philippe.leefsma
in reply to: tcuneio

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

Message 3 of 10
tcuneio
in reply to: philippe.leefsma

Thanks for looking into it.

Message 4 of 10
SEANT61
in reply to: tcuneio

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.
Message 5 of 10
tcuneio
in reply to: SEANT61

This line works in my vanilla 2015 version.

Message 6 of 10
SEANT61
in reply to: tcuneio

****.  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.
Message 7 of 10
tcuneio
in reply to: SEANT61

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.

Message 8 of 10
Gary_J_Orr
in reply to: tcuneio


@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
http://www.linkedin.com/in/garyorr

aka (current and past user names):
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
in reply to: Gary_J_Orr

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!

Message 10 of 10
Gary_J_Orr
in reply to: tcuneio

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
http://www.linkedin.com/in/garyorr

aka (current and past user names):
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)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost