Problem
The surfaces of SmartSolids can be extracted with the .FacetSolidAsShapes method. These areas could, for example, be added into the drawing to compare positions and size. When the SmartSolid element is not at zero, slight inaccuracies can be found when zoomed in due to rounding errors. This uncertainty is also present when the Smart Solid is withing the SWA (Solid Working Area). Here is an example of how to extract such shapes from SmartSolids and add them into the drawing:
' Somewhat inaccurate result: Sub extractshapefromsolid_inaccurate() Dim Enumerator As ElementEnumerator Dim enumShapes As ElementEnumerator Dim Sc As New ElementScanCriteria Sc.ExcludeAllTypes Sc.IncludeType msdElementTypeCellHeader Set Enumerator = ActiveModelReference.GraphicalElementCache.Scan Do While Enumerator.MoveNext If Enumerator.Current.IsSmartSolidElement Then 'Extract all shapes from the SmartSolid: Set enumShapes = Enumerator.Current.AsSmartSolidElement.FacetSolidAsShapes(100, 1000, 1000, 2 * Pi) Do While enumShapes.MoveNext ' Represent filled for comparing shapes enumShapes.Current.AsClosedElement.FillMode = msdFillModeFilled ' Insert shape into the drawing: ActiveModelReference.AddElement enumShapes.Current enumShapes.Current.Color = 3 ' The extracted shapes are at the point zero and need to be pushed towards the SmartSolid to compare their positions: enumShapes.Current.Move Enumerator.Current.AsSmartSolidElement.Origin ' Save the shift: enumShapes.Current.Rewrite Loop End If Loop End Sub
Lets start from a simple SmartSolid:
Then, after the above routine shapes, inaccuracies can be seen at each corner. The shape is shown here filled in with red:
A closer zoom shows this clearer:
Troubleshooting
If one shifts for extracting the SmartSolid element to zero, the result could be modified so that it provides accurate results as in the following example:
'Solution: Sub extractshapefromsolid_exact() Dim Enumerator As ElementEnumerator Dim enumShapes As ElementEnumerator Dim Sc As New ElementScanCriteria Dim pOrigin As Point3d Dim pOriginTemp As Point3d Sc.ExcludeAllTypes Sc.IncludeType msdElementTypeCellHeader Set Enumerator = ActiveModelReference.GraphicalElementCache.Scan Do While Enumerator.MoveNext If Enumerator.Current.IsSmartSolidElement Then pOrigin = Enumerator.Current.AsSmartSolidElement.Origin pOriginTemp.x = -pOrigin.x pOriginTemp.y = -pOrigin.y pOriginTemp.Z = -pOrigin.Z ' Temporary move of SmartSolids before extracting the Shapes ' This does not have to be referced because the shift only temporarily takes place and is not saved in the drawing Enumerator.Current.Move pOriginTemp Set enumShapes = Enumerator.Current.AsSmartSolidElement.FacetSolidAsShapes(100, 1000, 1000, 2 * Pi) Do While enumShapes.MoveNext enumShapes.Current.AsClosedElement.FillMode = msdFillModeFilled ActiveModelReference.AddElement enumShapes.Current enumShapes.Current.Color = 1 ' The shapes need to be moved to the same position ' The value for this must now be cached, because the SmartSolid was moved temporarily in between: enumShapes.Current.Move pOrigin enumShapes.Current.Rewrite Loop End If Loop End Sub
The exact result is shown in blue below. Here is the comparison: