Hello all!

Tell me please, how can I select all faces, moved by "move face"?

I need to select and change color of faces.

I modify macro https://forum.solidworks.com/thread/88370 to change color of faces, but it works with faces of boss-extrude or cut-extrude (for example) but  doesnt work with moved faces.

Sub Main()

 

    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim swPart As SldWorks.PartDoc

    Dim swFeat As SldWorks.Feature

    Dim swFaceFeat As SldWorks.Feature

    Dim swSelMgr As SldWorks.SelectionMgr

    Dim swFace As SldWorks.Face2

    Dim swEnt As SldWorks.Entity

    Dim faceArr As Variant

    Dim oneFace As Variant

    Dim status As Boolean

    Dim Area As Double

    Dim TotalArea As Double

 

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swPart = swModel

    Set swSelMgr = swModel.SelectionManager

        Set swFeat = swSelMgr.GetSelectedObject6(1, -1)

        faceArr = swFeat.GetFaces: If IsEmpty(faceArr) Then Exit Sub

        For Each oneFace In faceArr

            Set swFace = oneFace

            Set swEnt = swFace

            Set swFaceFeat = swFace.GetFeature

        

            If swFaceFeat Is swFeat Then

         vProps = swFace.GetMaterialPropertyValues2(1, Empty)

         vProps(0) = 0.5

         vProps(1) = 1

         vProps(2) = 0.5

         vProps(3) = 0

         vProps(4) = 0

         vProps(5) = 0

         vProps(6) = 0

         vProps(7) = 0

         vProps(8) = 0

         swFace.SetMaterialPropertyValues2 vProps, 1, Empty

 

  

swModel.ClearSelection2 True

            End If

 

        Next

End Sub

 

Is it possible to selet these faces?

 

 

Сообщение отредактировано: Alexey Kovalov

 

Hello! Maybe I can I select all faces, moved by feature "move face" in future manager? Anybody know the way I can do this? Regards, Alexey


Categories: API∕Macros

Comments
Last comment By: Simon Turner   Mon, 18 Sep 2017 09:01:11 GMT
Re: Macro to select all faces moved by feature "move face"

I use the attached macro to set colors inside parts or assemblies. Select a face or edge or point or feature or... anywhere and call any of the Color_XXX macros.

 

Andreas.

By: Andreas Killer  Thu, 15 Jun 2017 10:43:05 GMT
Re: Macro to select all faces moved by feature "move face"

Andreas, thanks for macro.

Unfortunately I got an error. See attached pictures.Screenshot_3.pngScreenshot_4.png

Is it compatible with SW2010?

By: Alexey Kovalov  Thu, 15 Jun 2017 10:58:18 GMT
Re: Macro to select all faces moved by feature "move face"

Is it compatible with SW2010?

IMHO yes, otherwise you should get an error 2 lines above on swSelectType_e.swSelFTRFOLDER, or I'm wrong?

 

Anyway, I've written that macro with SW2016, so maybe the compiler has a little issue with the references:

Try to remove the reference to "SldWorks 2010 Type Library", save, close and reopen, then set the reference again.

 

If that doesn't work change the Dim line to

  Dim swFtrFolder As Object 'SldWorks.FeatureFolder

 

Andreas.

By: Andreas Killer  Thu, 15 Jun 2017 11:20:21 GMT
Re: Macro to select all faces moved by feature "move face"

Hello, Andreas!

Thanks.

I changed Dim line as you write and macro became work.

But if I choose boss-extrude feature then macro change color for all faces of the part (solid). Is it correct? If I choose move face feature I got an error.

I need to choose move face feature and change color only for move faces.

Please see attached files.

Regards,

Alexey

By: Alexey Kovalov  Fri, 16 Jun 2017 05:47:40 GMT
Re: Macro to select all faces moved by feature "move face"

Hello!

I need to change color only for faces moved by "Move face" feature.

I.e. I run macro, choose "Move face" feature in features manager, and moved faces change its color (see attached pics). But using your macro I choose "move face" and all the body change it color (not only moved faces). Also I get an error (see screenshot 1).

Maybe Im doing something wrong.

Alexey

By: Alexey Kovalov  Thu, 14 Sep 2017 05:08:49 GMT
Re: Macro to select all faces moved by feature "move face"

Hello!

Is it possible at all?

Regards, Alexey

By: Alexey Kovalov  Mon, 18 Sep 2017 08:01:31 GMT
Re: Macro to select all faces moved by feature "move face"

Dim swApp As SldWorks.SldWorks

Dim Part As ModelDoc2

 

Sub main()

    Dim selmgr As SelectionMgr

    Dim myFeat As Feature

    Dim sa As Variant

    Dim myFace As Face2

    Dim i As Integer

    Dim vProps As Variant

   

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc

    If Part Is Nothing Then Exit Sub

    If Part.GetType <> 1 Then Exit Sub

    Set selmgr = Part.SelectionManager

    If selmgr.GetSelectedObjectCount2(-1) <> 1 Then Exit Sub

    If selmgr.GetSelectedObjectType3(1, -1) <> swSelBODYFEATURES Then Exit Sub

    Set myFeat = selmgr.GetSelectedObject6(1, -1)

    sa = myFeat.GetAffectedFaces

    If IsEmpty(sa) Then Exit Sub

    Part.ClearSelection2 True

    For i = 0 To UBound(sa)

        Set myFace = sa(i)

        vProps = myFace.GetMaterialPropertyValues2(1, Empty)

         vProps(0) = 0.5

         vProps(1) = 1

         vProps(2) = 0.5

         vProps(3) = 0

         vProps(4) = 0

         vProps(5) = 0

         vProps(6) = 0

         vProps(7) = 0

         vProps(8) = 0

         myFace.SetMaterialPropertyValues2 vProps, 1, Empty

    Next

End Sub

By: Simon Turner  Mon, 18 Sep 2017 09:01:11 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.