3 Replies Latest reply on Oct 5, 2015 9:58 AM by Janos David Ommert

    GetComponent fails

    Janos David Ommert

      I have a case in which GetComponent fails. (returns nothing)


      I have a assembly with some components in it. There are 2D sketches with points on the assembly. The sketches are referenced to the surfaces of the components but belong to the assembly. Maiby thats the problem why GetComponent fails.


      I need to get the normal vector of the surface the points are on. It's for export into a csv file for processing by a laser tracker.

      I can get the normal vector without problems but it's relativ to the components origin. I need it relativ to the assemblys origin. So i need to transform it. For that i need to get the transformation of the component. To get the transformation i need to get the components object. And thats the point my code fails.

      "Set Component = Entity.GetComponent" Component is nothing.


      Anything i am doing wrong?

      Is there another way to get the transform?


                  'get face of the sketch
                  Set SketchFace = swSketch.GetReferenceEntity(EntityType)
                  'check if sketch was been made on a face
                  If EntityType <> swSelFACES Then
                      MsgBox "Die Skizze hat keine Fläche als Referenz: " & swFeat.Description, vbCritical
                      Exit Sub
                  End If
                  'get normal of face
                  NormalArray(0) = SketchFace.Normal(0)
                  NormalArray(1) = SketchFace.Normal(1)
                  NormalArray(2) = SketchFace.Normal(2)
                  'transform normal to assembly origin
                  Set NormalVector = swMathUtil.CreateVector(NormalArray)
                  Set Entity = SketchFace
                  Set Component = Entity.GetComponent
                  Set NormalVector = NormalVector.MultiplyTransform(Component.Transform.Inverse)
                  NormalX = NormalVector.ArrayData(0)
                  NormalY = NormalVector.ArrayData(1)
                  NormalZ = NormalVector.ArrayData(2)
        • Re: GetComponent fails
          Josh Brady

          What happens if you select the face and then use GetSelectedObjectsComponent?

          • Re: GetComponent fails
            Janos David Ommert

            I found the problem.

            Found this in the documentation: "When you create a sketch relation, an internal entity may also be created to define that sketch relation."

            So what happend was that SolidWorks created a internal entity for the relation of the sketch to the face. So GetReferenceEntity gives that internal entity, which does not belong to the component. Thats also why it can't be selected.


            I solved this by getting the sketch relations with the SketchRelationManager and got the relation to the components face by using GetDefinitionEntities2. From there i finaly get the component by using GetComponent on the definition entity.

            It's a little bit messy code but it works.

            Took me quite some time to get how relations work with the relation manager, it wasnt easy for me.