1 Reply Latest reply on May 23, 2016 4:15 AM by Simon Fritz

    addRelation between referenceplane and 3dsketchplane

    Simon Fritz

      Hey,

       

      i try to add a COINCIDENT Relation to a 3dsketchplane to a referenceplane of the assembly. How can i add this relation? I didnt found a way to convert a selected Referenceplane to an entity ( Sketch.addrelation (entity, relationtype)   )

       

      Do you know how to add sutch a relation?

        • Re: addRelation between referenceplane and 3dsketchplane
          Simon Fritz

          This is how i solved my problem finally! Thx to the Solidworks Support!!!

           

           

          private void addConstraint(ModelDoc2 _model)

                  {

                      // errorHandling: http://help.solidworks.com/2013/English/api/sldworksapi/Constrain_Sketch_Example_CSharp.htm

                      AssemblyDoc _swAssembly = (AssemblyDoc)_model;

                      Sketch swSketch;

                      SelectionMgr swSelMgr = _model.SelectionManager;

                      SketchRelationManager swSkeRelMgr;

                      int intstatus;

                      bool boolstatus;

           

           

                      // Selects the 3DSketch1 and opens it

                      Feature swfeat = getFeatureByName(_model, "3DSketch1");

                      boolstatus = swfeat.Select(true);

                      _model.EditSketch();

           

           

                      // Selects two Planes and adds a COINCIDENT Relation between them

                      boolstatus = _model.Extension.SelectByID2("TCPX@Schunk_PG-plus_70-2@Assem1", "PLANE", 0, 0, 0, false, 0, null, 0);

                      boolstatus = _model.Extension.SelectByID2("Plane1", "SKETCHSURFACES", 0, 0, 0, true, 0, null, 0);

                      _model.SketchAddConstraints("sgCOINCIDENT");

           

           

                      // Delete all Relations from sketch

                      swSketch = (Sketch)swfeat.GetSpecificFeature2();

                      swSkeRelMgr = swSketch.RelationManager;

                      swSkeRelMgr.DeleteAllRelations();

           

           

                      // Close Sketch and clear Selection

                      _model.ClearSelection2(true);

                      _model.InsertSketch2(true);

                      _model.EditRebuild3();

           

           

                      // Add assembly-mate between the same two planes, so the TCP moves coincidently

                      boolstatus = _model.Extension.SelectByID2("TCPX@Schunk_PG-plus_70-2@Assem1", "PLANE", 0, 0, 0, false, 0, null, 0);

                      boolstatus = _model.Extension.SelectByID2("Plane1@3DSketch1", "EXTSKETCHSURFACES", 0, 0, 0, true, 0, null, 0);

                      _swAssembly.AddMate5(0, 0, true, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out intstatus);

           

           

                      // Clear Selection and Rebuild assembly

                      _model.ClearSelection2(true);

                      _model.EditRebuild3();

           

           

                      // Delete Mate

                      // Find mate by using the "Featurebyname" - "MateGroup"

                      // https://forum.solidworks.com/thread/59399

                  }