You are currently reviewing an older revision of this page.
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
enumShapes
Sc
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:
enumShapes = Enumerator.Current.AsSmartSolidElement.FacetSolidAsShapes(100, 1000, 1000, 2 * Pi)
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
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:
extractshapefromsolid_exact()
pOrigin
Point3d
pOriginTemp
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
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
The exact result is shown in blue below. Here is the comparison: