7 Replies Latest reply on Jun 8, 2017 8:24 PM by Yong Ning

    GetAttachedEntities2????

    Yong Ning

      Follow  key code →  SwPt1.x  → Is not the target demand coordinates

       

             Ss = SwAnn.GetAttachedEntities2

             Set SwPt1 = Ss(0)

             SwPt1.X → Is not the target demand coordinates

             SwPt1.Y → Is the target demand coordinates

       

       

      GetAttachedEntities2.jpg

       

       

       

       

      Private Sub del20161224()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

             Set SwApp = Application.SldWorks

             Set SwModel = SwApp.ActiveDoc

         Dim SwDraw As DrawingDoc

             Set SwDraw = SwModel

         Dim SwView As View

             Set SwView = SwDraw.GetFirstView '

             Set SwView = SwView.GetNextView

             'Set SwView = SwView.GetNextView

             oScale = 1 'SwView.ScaleDecimal

             SwView.ScaleDecimal = oScale

             SwDraw.ActivateView SwView.Name

         Dim vPos, vPts(1)

             vPts(0) = 0

             vPts(1) = 0

             SwView.SetXform vPts

         Dim swSelMgr As SelectionMgr

             Set swSelMgr = SwModel.SelectionManager

         Dim SwDispDim As DisplayDimension, SwDim As Dimension, SwAnn As Annotation

             Set SwDispDim = swSelMgr.GetSelectedObject5(1)

             Set SwAnn = SwDispDim.GetAnnotation

             Ss = SwAnn.GetAttachedEntities2

         Dim SwPt1 As SketchPoint, SwPt2 As SketchPoint

             Set SwPt1 = Ss(0)

             Debug.Print SwPt1.X, SwPt1.Y

             Stop

       

         Dim DimPt, SwSketchLine As SketchLine, SwSktSeg As SketchSegment

             Set SwAnn = SwDispDim.GetAnnotation

             DimPt = SwAnn.GetPosition

             'Set SwSktSeg = SwModel.CreateLine2(vPts(0), vPts(0), 0, DimPt(0) / oScale, DimPt(1) / oScale, 0)

             Set SwSktSeg = SwModel.CreateLine2(SwPt1.X, SwPt1.Y, 0, DimPt(0) / oScale, DimPt(1) / oScale, 0)

             SwSktSeg.Layer = "尺寸线"

             SwView.UseSheetScale = True

             SwModel.ForceRebuild3 True

             ''

             Stop

             Stop

           

      End Sub

        • Re: GetAttachedEntities2????
          Peter Brinkhuis

          What annotation do you want to get the end points from? From the dimension? What results do you expect and what are the results that you get?

           

          I noticed that GetAttachedEntities2 has been superseded for a long time, you should use GetAttachedEntities3.

           

          Are you sure your annotation is attached to vertices (points)? It could also be attached to a line, surface or sketch point. See the info in the link for more details.

            • Re: GetAttachedEntities2????
              Yong Ning

              Thank you for your reply

              In dimension, use  SwAnn.GetAttachedEntities3 , position is error.

               

              1GetAttachedEntities2.jpg

               

               

              2GetAttachedEntities2.jpg

                • Re: GetAttachedEntities2????
                  Yong Ning

                  Private Sub del255()

                    

                         ''

                     Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                         Set SwApp = Application.SldWorks

                         Set SwModel = SwApp.ActiveDoc

                     Dim SwSelMgr As SelectionMgr

                         Set SwSelMgr = SwModel.SelectionManager

                     Dim SwDraw As DrawingDoc

                        

                         Set SwDraw = SwModel

                     Dim SwView As View, Pos

                     Dim Pt2(1), oScale

                         Set SwView = SwDraw.GetFirstView

                        

                         Set SwView = SwView.GetNextView

                         oScale = 1 / SwView.ScaleDecimal

                         SwDraw.ActivateView SwView.Name

                   

                         Pt2(0) = 200 / 1000

                         Pt2(1) = 300 / 1000

                         'SwView.Position = Pt2

                         SwModel.ForceRebuild3 True

                        

                         Var = SwView.GetOutline

                         ''''

                         xx1 = Var(0) * oScale

                         xx2 = Var(2) * oScale

                         yy1 = Var(1) * oScale

                         yy2 = Var(3) * oScale

                         Ww = xx2 - xx1

                         Hh = yy2 - yy1

                         Debug.Print Ww * 1000, Hh * 1000

                         Debug.Print xx1 * 1000, yy1 * 1000

                         Debug.Print xx2 * 100#, yy2 * 1000

                         ''

                         SwDraw.SketchRectangle -Ww / 2, -Hh / 2, 0, Ww / 2, Hh / 2, 0, True

                         SwModel.ForceRebuild3 True

                        

                        

                  End Sub

                  • Re: GetAttachedEntities2????
                    Peter Brinkhuis

                    I copied your code and removed the section where you move the drawing view. I then select a dimension and run the macro. If you define ss properly (as you should, just add "option explicit" to the top of your files to make sure every variable is defined) ss has to be of type variant.

                     

                    ss will be an array of objects, one object for every entity (line, circle, vertex) that the dimension is connected to. If it is a diameter dimension, it is connected to one entity and ss will only contain one object. With the line "Set SwPt1 = ss(0)" you are trying to put the content of the object into a sketchpoint. That isn't going to work. You also assume it always contains two points, this isn't true for all dimension.

                     

                    I think you need to add many checks:

                    • To make sure a dimension is selected instead of just doing this below. You could put the complete selection in an object, count them and determine the type.
                      • Dim SwDispDim As DisplayDimension
                      • Set SwDispDim = swSelMgr.GetSelectedObject5(1)
                    • Add something like this:
                      • If SwAnn.GetType = 4 Then  'selected item is a dimension
                    • Count the length of ss to make sure it has two items in it

                     

                    I tried the following, but that only give an array of Longs with the value 1 as the type, not explanations like the help tells you.

                         Dim typearray as variant      

                         typeArray = SwAnn.GetAttachedEntityTypes

                         Dim i As Integer

                         For i = 0 To UBound(typeArray)

                             Debug.Print typeArray(i)

                         Next i

                      • Re: GetAttachedEntities2????
                        Yong Ning

                        swSelectType_e

                        Specifies values for possible types of IDs returned. You can use the values listed in the second column, if available, for programmatic selection.

                         

                        swSelectType_e

                        ModelDocExtension::SelectByID2
                        string

                        SelectionMgr::GetSelectedObject6
                        return value

                        Feature::GetSpecificFeature2
                        return value

                        swSelNOTHING 

                         

                         

                         

                        swSelEDGES

                        "EDGE"

                        Edge

                         

                        swSelFACES

                        "FACE"

                        Face2

                         

                        swSelVERTICES

                        "VERTEX"

                        Vertex

                         

                        swSelDATUMPLANES

                        "PLANE"

                        Feature2

                        RefPlane

                        swSelDATUMAXES

                        "AXIS"

                        Feature2

                        RefAxis

                        swSelDATUMPOINTS

                        "DATUMPOINT"

                        Feature1

                        No specific interface

                        swSelOLEITEMS

                        "OLEITEM"

                        Not Supported

                         

                        swSelATTRIBUTES

                        "ATTRIBUTE"

                        Feature1

                        Attribute

                        swSelSKETCHES

                        "SKETCH"

                        Feature2

                        Sketch

                        swSelSKETCHSEGS

                        "SKETCHSEGMENT"

                        SketchSegment

                         

                        swSelSKETCHPOINTS

                        "SKETCHPOINT"

                        SketchPoint

                         

                        swSelDRAWINGVIEWS

                        "DRAWINGVIEW"

                        View

                         

                        swSelGTOLS

                        "GTOL"

                        Gtol

                         

                        swSelDIMENSIONS

                        "DIMENSION"

                        DisplayDimension

                         

                        swSelNOTES

                        "NOTE"

                        Note

                         

                        swSelSECTIONLINES

                        "SECTIONLINE"

                        Feature1

                        DrSection

                        swSelDETAILCIRCLES

                        "DETAILCIRCLE"

                        Feature1

                        DetailCircle

                        swSelSECTIONTEXT

                        "SECTIONTEXT"

                         

                         

                        swSelSHEETS

                        "SHEET"

                        Sheet

                         

                        swSelCOMPONENTS

                        "COMPONENT"

                        Component2

                         

                        swSelMATES

                        "MATE"

                        Feature2

                        Mate

                        swSelBODYFEATURES

                        "BODYFEATURE"3

                        Feature1

                        No specific interface

                        swSelREFCURVES

                        "REFCURVE"

                        Feature1

                        ReferenceCurve

                        swSelEXTSKETCHSEGS

                        "EXTSKETCHSEGMENT"

                        SketchSegment

                         

                        swSelEXTSKETCHPOINTS

                        "EXTSKETCHPOINT"

                        SketchPoint

                         

                        swSelHELIX

                        "HELIX"

                         

                         

                        swSelREFERENCECURVES

                        "REFERENCECURVES"

                        Feature1

                        ReferenceCurve

                        swSelREFSURFACES

                        "REFSURFACE"

                         

                         

                        swSelCENTERMARKS

                        "CENTERMARKS"

                        Not supported

                         

                        swSelINCONTEXTFEAT

                        "INCONTEXTFEAT"

                         

                         

                        swSelMATEGROUP

                        "MATEGROUP"

                         

                         

                        swSelBREAKLINES

                        "BREAKLINE"

                        BreakLine

                         

                        swSelINCONTEXTFEATS

                        "INCONTEXTFEATS"

                         

                         

                        swSelMATEGROUPS

                        "MATEGROUPS"

                         

                         

                        swSelSKETCHTEXT

                        "SKETCHTEXT"

                         

                         

                        swSelSFSYMBOLS

                        "SFSYMBOL"

                        SFSymbol

                         

                        swSelDATUMTAGS

                        "DATUMTAG"

                        DatumTag

                         

                        swSelCOMPPATTERN

                        "COMPPATTERN"

                         

                         

                        swSelWELDS

                        "WELD"

                        WeldSymbol

                         

                        swSelCTHREADS

                        "CTHREAD"

                        Feature or CThread4

                        CosmeticThreadFeatureData

                        swSelDTMTARGS

                        "DTMTARG"

                        DatumTargetSym

                         

                        swSelPOINTREFS

                        "POINTREF"

                         

                         

                        swSelDCABINETS

                        "DCABINET"

                         

                         

                        swSelEXPLVIEWS

                        "EXPLODEVIEWS"

                         

                         

                        swSelEXPLSTEPS

                        "EXPLODESTEPS"

                         

                         

                        swSelEXPLLINES

                        "EXPLODELINES"

                         

                         

                        swSelSILHOUETTES

                        "SILHOUETTE"

                         

                         

                        swSelCONFIGURATIONS

                        "CONFIGURATIONS"

                        Feature1

                        Configuration

                        swSelOBJHANDLES

                         

                         

                         

                        swSelARROWS

                        "VIEWARROW"

                        ProjectionArrow

                         

                        swSelZONES

                        "ZONES"

                         

                         

                        swSelREFEDGES

                        "REFERENCE-EDGE"

                        Edge

                         

                        swSelREFFACES

                         

                         

                         

                        swSelREFSILHOUETTE

                         

                        Feature1

                         

                        swSelBOMS

                        "BOM"

                         

                         

                        swSelEQNFOLDER

                        "EQNFOLDER"

                         

                         

                        swSelSKETCHHATCH

                        "SKETCHHATCH"

                         

                         

                        swSelIMPORTFOLDER

                        "IMPORTFOLDER"

                         

                         

                        swSelVIEWERHYPERLINK 

                        "HYPERLINK"

                         

                         

                        swSelMIDPOINTS

                         

                         

                         

                        swSelCUSTOMSYMBOLS

                        "CUSTOMSYMBOL"

                        CustomSymbol

                         

                        swSelCOORDSYS

                        "COORDSYS"

                         

                         

                        swSelDATUMLINES

                        "REFLINE"

                         

                         

                        swSelROUTECURVES

                         

                         

                         

                        swSelBOMTEMPS

                        "BOMTEMP"

                         

                         

                        swSelROUTEPOINTS

                        "ROUTEPOINT'

                         

                         

                        swSelCONNECTIONPOINTS

                        "CONNECTIONPOINT"

                         

                         

                        swSelROUTESWEEPS

                         

                         

                         

                        swSelPOSGROUP

                        "POSGROUP"

                         

                         

                        swSelBROWSERITEM

                        "BROWSERITEM"

                         

                         

                        swSelFABRICATEDROUTE 

                        "ROUTEFABRICATED"

                         

                         

                        swSelSKETCHPOINTFEAT 

                        "SKETCHPOINTFEAT"

                         

                         

                        swSelCOMPSDONTOVERRIDE

                         

                         

                         

                        swSelLIGHTS

                        "LIGHTS"

                         

                         

                        swSelWIREBODIES

                         

                         

                         

                        swSelSURFACEBODIES

                        "SURFACEBODY"

                         

                         

                        swSelSOLIDBODIES

                        "SOLIDBODY"

                         

                         

                        swSelFRAMEPOINT

                        "FRAMEPOINT"

                         

                         

                        swSelSURFBODIESFIRST

                         

                         

                         

                        swSelMANIPULATORS

                        "MANIPULATOR"

                         

                         

                        swSelPICTUREBODIES

                        "PICTURE BODY"

                         

                         

                        swSelSOLIDBODIESFIRST

                         

                         

                         

                        swSelLEADERS

                        "LEADER"

                         

                         

                        swSelDOWELSYMS

                        "DOWLELSYM"

                        DowelSymbol

                         

                        swSelEXTSKETCHTEXT

                        "EXTSKETCHTEXT"

                         

                         

                        swSelBLOCKINST

                        "BLOCKINST"

                        BlockInstance

                         

                        swSelFTRFOLDER

                        "FTRFOLDER"

                         

                         

                        swSelSKETCHREGION

                        "SKETCHREGION"

                         

                         

                        swSelSKETCHCONTOUR

                        "SKETCHCONTOUR"

                         

                         

                        swSelBOMFEATURES

                        "BOMFEATURE"

                         

                         

                        swSelANNOTATIONTABLES

                        "ANNOTATIONTABLES"

                         

                         

                        swSelBLOCKDEF

                        "BLOCKDEF"

                         

                         

                        swSelCENTERMARKSYMS

                        "CENTERMARKSYMS"

                         

                         

                        swSelCENTERLINES

                        "CENTERLINE"

                         

                         

                        swSelHOLETABLEFEATS

                        "HOLETABLE"

                         

                        HoleTable object

                        swSelHOLETABLEAXES

                        "HOLETABLEAXIS"

                         

                         

                        swSelWELDMENT

                        "WELDMENT"

                         

                         

                        swSelSUBWELDFOLDER

                        "SUBWELDMENT"

                         

                         

                        swSelREVISIONTABLE

                        "REVISIONTABLE"

                         

                         

                        swSelBODYFOLDER

                        "BDYFOLDER"

                         

                        BodyFolder object

                        swSelSUBSKETCHINST

                        "SUBSKETCHINST"

                         

                         

                        swSelREVISIONTABLEFEAT

                        "REVISIONTABLEFEAT"

                         

                         

                        swSelCAMERAS

                        "CAMERAS"

                         

                        Camera object

                        swSelSIMULATION

                        "SIMULATION"

                         

                        Simulation object

                        swSelSIMELEMENT

                        "SIMULATION_ELEMENT"

                         

                         

                        swSelSUBATOMFOLDER

                         

                         

                         

                        swSelEMBEDLINKDOC

                        "EMBEDLINKDOC"

                         

                         

                        swSelJOURNAL

                        "JOURNAL"

                         

                         

                        swSelDOCSFOLDER

                        "DOCSFOLDER"

                         

                         

                        swSelCOMMENTSFOLDER

                        "COMMENTSFOLDER"

                         

                        CommentFolder

                        swSelCOMMENT

                        "COMMENT"

                        Comment

                         

                        swSelWELDBEADS3

                        "WELDBEADS"

                         

                         

                        swSelGENERALTABLEFEAT

                        "GENERALTABLEFEAT"

                         

                         

                        swSelMATESUPPLEMENT

                        "MATESUPPLEMENT"

                        MateLoadReference

                         

                        swSelEVERYTHING

                         

                         

                         

                        swSelLOCATIONS

                         

                         

                         

                        swSelUNSUPPORTED

                         

                         

                         

                         

                        1 Use Feature::GetSpecificFeature2 to get the interface shown in the fourth column.

                        2 Use QueryInterface to get the interface shown in the fourth column.

                        3 Use swSelWELDBEADS to select caterpillar or end-treatment weld beads in drawings. To select fillet bead features, use "BODYFEATURE" with ModelDocExtension::SelectByID2.

                        4 Feature or CThread depending on whether you select the cosmetic thread feature in a part or assembly or you select the cosmetic thread annotation in a drawing.

                          • Re: GetAttachedEntities2????
                            Yong Ning

                            Replace referenced edge of a drawing dimension ... | SOLIDWORKS Forums  https://forum.solidworks.com/message/264352#comment-264352

                             

                             

                            ‘‘’’

                             

                             

                            Private Sub ll()

                               Dim Params, RegEdge, Obj

                               Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                                   Set SwApp = Application.SldWorks

                                   Set SwModel = SwApp.ActiveDoc

                               Dim SwSelMgr As SelectionMgr

                                   Set SwSelMgr = SwModel.SelectionManager

                               Dim SwDispDim As DisplayDimension, SwDim As Dimension, SwAnn As Annotation

                               Dim SwEdge As Edge, SwPt As SketchPoint  ' SilhouetteEdge

                                   For ii = 1 To SwSelMgr.GetSelectedObjectCount

                                        Set SwDispDim = SwSelMgr.GetSelectedObject5(1)

                                        Set SwAnn = SwDispDim.GetAnnotation

                                        Params = SwAnn.GetAttachedEntities3

                                        For Each Obj In Params

                                            'Set SwPt = Obj

                                            Obj.Select True

                                            Stop

                                        Next Obj

                                   Next ii

                             

                            End Sub

                             

                            *************************************************************************************

                            ‘‘‘’’’''

                            Private Sub del()

                                Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                                    Set SwApp = Application.SldWorks

                                    Set SwModel = SwApp.ActiveDoc

                                Dim SwSelMgr As SelectionMgr

                                    Set SwSelMgr = SwModel.SelectionManager

                                Dim SwDim As Dimension

                                Dim SwDispDim As DisplayDimension, SwAnn As Annotation

                                Dim vEntArr, vEntTypeArr

                                Dim SwPt As SketchPoint, SwLine As SketchLine

                                    For ii = 1 To 20

                                        Set SwDispDim = SwSelMgr.GetSelectedObject5(ii)

                                        If Not SwDispDim Is Nothing Then

                                            Set SwAnn = SwDispDim.GetAnnotation

                                            vEntArr = SwAnn.GetAttachedEntities

                                            vEntTypeArr = SwAnn.GetAttachedEntityTypes

                                            ''

                                            For jj = 0 To UBound(vEntTypeArr)

                                                Debug.Print SwDispDim.GetDimension.FullName,

                                                If vEntTypeArr(jj) = swSelSKETCHPOINTS Then

                                                    Debug.Print ii, jj, vEntTypeArr(jj), vEntTypeArr(jj) = swSelSKETCHPOINTS,

                                                    Set SwPt = vEntArr(jj)

                                                    With SwPt

                                                        Debug.Print .X, .Y, .Z

                                                    End With

                                                ElseIf vEntTypeArr(jj) = swSelSKETCHSEGS Then

                                                    Debug.Print vEntTypeArr(jj), vEntTypeArr(jj) = swSelSKETCHSEGS

                                                    Set SwLine = vEntArr(jj)

                                              

                                                End If

                                            Next jj

                                            'Stop

                                        End If

                                       

                                    Next ii

                                  

                            End Sub

                              • Re: GetAttachedEntities2????
                                Yong Ning

                                Private Sub del3()

                                   Dim Str

                                   Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                                       Set SwApp = Application.SldWorks

                                       Set SwModel = SwApp.ActiveDoc

                                   Dim SwDraw As DrawingDoc

                                       Set SwDraw = SwModel

                                   Dim SwSelMgr As SelectionMgr

                                       Set SwSelMgr = SwDraw.SelectionManager

                                   Dim SwView As View

                                       Set SwView = SwSelMgr.GetSelectedObject5(1)

                                       Set SwModel = SwView.ReferencedDocument

                                       Debug.Print SwModel.GetPathName

                                       Set SwSelMgr = SwModel.SelectionManager

                                       ''

                                   Dim SwDim As Dimension, SwDispDim As DisplayDimension

                                 

                                 

                                 

                                       SwModel.ClearSelection2 True

                                       Str = "RD1@Annotations"

                                       Str = "RD1@注解"

                                       tmp = SwModel.Extension.SelectByID2(Str, "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

                                       'Debug.Print SwModel.GetPathName, SwSelMgr.GetSelectedObjectCount

                                       Stop

                                       Set SwDispDim = SwSelMgr.GetSelectedObject5(1)

                                       Debug.Print SwDispDim.GetDimension.FullName

                                       Stop

                                   Dim SwAnn As Annotation

                                       Set SwAnn = SwDispDim.GetAnnotation

                                     

                                   Dim Ss, Ss1

                                   Dim SwEnt  As Entity

                                   Dim Xx As Double, Yy As Double, Zz As Double

                                       With SwAnn

                                           Ss1 = .GetAttachedEntityTypes

                                           Ss = .GetAttachedEntities

                                           Stop

                                       End With

                                       Debug.Print SwAnn.GetName

                                       Stop

                                       Stop

                                      

                                       If Ss1(0) = swSelEDGES Then

                                           Set SwEnt = Ss(0)

                                           tmp = SwView.SelectEntity(SwEnt, False)

                                           Stop

                                       End If

                                       Set SwDispDim = SwDraw.AddDimension2(Xx, Yy, Zz)

                                      

                                 

                                 

                                     

                                End Sub