Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

API: generating Unfolded view

Status
Not open for further replies.

rocheey

Industrial
Joined
Jan 21, 2001
Messages
230
Location
US
The 'create flat pattern view from Model view" call runs too slowly; and is not needed; Im to be exporting the unfolded geom from the drawing view.

I know that just suppressing the flat pattern, or suppressing the process bends runs quicker, but I cannot figure out how to, from code, set the 'normal to' whatever plane was used to create the Flat-Pettern or 'Process-Bends' feature.

Im unable to get the plane reference from 2001 (not plus) or earlier, and while I can manually select the sketch subfeature and then click 'normal to', I am unable to select the SUB feature thru code - the selection seems to stay on the 'parent' feature.

Any ideas/workarounds? Its gotta be 2001 compatible, no 20001 plus calls ...
 
Have you tired recording a macro and performing that operation? Once you have done that you can edit that macro and get most of the API code from that.

I hope that helps, Scott Baugh, CSWP [spin]
credence69@REMOVEhotmail.com
 
Possibly you could use the show named view. This would of course require adding the named view ahead of time perhaps a macro could be used to assist this also. Use the same naming convention for the plane and named view to build the association.

example code
Part.ShowNamedView2 "*Top", 5

Bill Briggs, CSWP
 
I was writing this as a function, so I had hoped to be able to use a call that returned a value, but hey, at least it's working now.

Pass the routine a ModelDoc object, and it will Flatten the model, and return a Boolean success code:

'---------------------------------------------------------------------------------------
' Procedure : Flatten
' DateTime : 4/8/2002 20:33
' Author : rocheey
' Purpose : Flattens a Sheet metal Model, and sets the flattened face to
' normal.
' Comments : Pass the routine a Partdoc/ModelDoc and it will attempt to
' suppress the feature. The Function returns TRUE if successful.
'
'---------------------------------------------------------------------------------------
'
Function Flatten(ModelDoc As Object) As Boolean

Const ParseString As String = "FlatPatternProcessBends" ' CASE SENSITIVE! Do Not Change!
Const NormalView As String = "*Normal To"
Const swDocPART As Long = 1

Dim featCount As Long
Dim Feat As Object, SubFeat As Object
Dim featname As String
Dim Success As Boolean

' check DocType, make sure not AssemblyDoc or DrawingDoc
If ModelDoc.getType <> swDocPART Then Exit Function ' return 0

featCount = ModelDoc.GetFeatureCount ' get number of features to Loop thru
For I% = featCount To 1 Step -1 ' Loop backwards thru the features (starting at bottom)
Set Feat = ModelDoc.FeatureByPositionReverse(featCount - I)
featname = Feat.GetTypeName ' get name of feature TYPE, niot feature name
FoundFeature% = InStr(ParseString, featname) ' is it one of our features?
If FoundFeature% Then
MainFeatName$ = Feat.Name ' yessir, I believe it is.
Exit For ' no sense in looking any further
End If
Next I%

If FoundFeature% = 0 Then Exit Function ' If not Sheet metal related, get outta here

Feat.select (False) ' select the Feature, and toggle suppression in our main feature
If FoundFeature% = 1 Then 'Flat Pattern
If Feat.IsSuppressed Then ' Must UNsuppress flat pattern
Success = ModelDoc.EditUnsuppress2 ' unsupress FLATPATTERN,
Else
Success = True ' its already been done for us :)
End If
If Not Success Then Exit Function
ElseIf FoundFeature% = 12 Then ' Process bends
If Not (Feat.IsSuppressed) Then ' Must SUPPRESS Process Bends
Success = ModelDoc.Editsuppress2 ' Suppress Feature
Else
Success = True ' its already been done for us :)
End If
If Not Success Then Exit Function
End If

' Now select the first subfeature
Set SubFeat = Feat.GetFirstSubFeature
Do While Not SubFeat Is Nothing ' While we have a valid Sub-feature
featname = SubFeat.GetTypeName
If featname = &quot;ProfileFeature&quot; Then ' we have our man
SubFeatName$ = SubFeat.Name
FoundFeat% = 1
Exit Do
End If
Set SubFeat = SubFeat.GetNextSubFeature
Loop ' Continue until the last Sub-feature is done

If FoundFeat% = 0 Then Exit Function

ModelDoc.ClearSelection ' clear the selection object
Success = ModelDoc.SelectByID(SubFeatName$, &quot;SKETCH&quot;, 0, 0, 0) ' select the sub feature sketch
ModelDoc.ShowNamedView2 NormalView, 0

Flatten = Success

End Function
 
rocheey,

Bill,

>I need to create a view normal to a plane. Is there a way to do this
through the
>API?
you will have to first select the plane and then call:

rocheey, you may be able to select the sktch and do this also

ModelDoc2::ShowNamedView2(&quot;*Normal To&quot;)
ModelDoc2::NameView

Kind regards,
Trevor D'Arcy-Evans
APIsupportEU@SolidWorks.com
SolidWorks API Support Europe
+44 1223 346904

Bill Briggs, CSWP
bbriggs@cybllings.com
 
That is exactly what i did... and while it seems to always work with any config on one particular part, it always seems to fail once I load up a second, or different part, Its very strange behaviour.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top