×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

API: generating Unfolded view

API: generating Unfolded view

API: generating Unfolded view

(OP)
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 ...

RE: API: generating Unfolded view

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

RE: API: generating Unfolded view

(OP)
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 = "ProfileFeature" 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$, "SKETCH", 0, 0, 0)   ' select the sub feature sketch
    ModelDoc.ShowNamedView2 NormalView, 0

    Flatten = Success
    
End Function

RE: API: generating Unfolded view

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("*Normal To")
    ModelDoc2::NameView

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

Bill Briggs, CSWP
bbriggs@cybllings.com
www.cybllings.com

RE: API: generating Unfolded view

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources