1 Reply Latest reply on May 3, 2018 12:37 PM by Simon Turner

    Insertion point MakeSketchBlockFromSelected

    Todd Carpenter

      Hi All,


      I'm having an issue controlling where my insertion point is located when I create a block using the API.  When I use the API, the point is always center of the height of the geometry, and way to the right.  I've inserted the drawing geometry at 0,0 when I import it, and I tried supplying an insertion point of 0,0 but it doesn't seem to change anything.  Here's the code I'm using, (the important parts anyway), nothing fancy:


      SelectionMgr swSelMgr;
      swSelMgr = (SelectionMgr)swModel.SelectionManager;
      // Write the block out.
      MathUtility swMathUtil = swApp.IGetMathUtility();
      MathPoint swMathPoint;
      double[] nPt = new double[3] { 0.0, 0.0, 0.0 };
      Object vPt = nPt;
      swMathPoint = (MathPoint)swMathUtil.CreatePoint(vPt);
      SketchBlockDefinition swBlockDefinition = null;
      swBlockDefinition = ((SketchBlockDefinition)(swModel.SketchManager.MakeSketchBlockFromSelected(swMathPoint)));
      string blockFileName = sDwgFileName.Replace(".dwg", ".sldblk");


      Am I doing something wrong?  When I create the block by hand, the insertion point is always the lower left corner of the geometry bounding box - I initially thought that would be the default behavior in the API as well - I was obviously wrong.


      Any help would be appreciated - thanks!

        • Re: Insertion point MakeSketchBlockFromSelected
          Simon Turner

          I use almost exactly the same code to create my blocks.

          There is a minor difference in that I don't use swModelDocExt.SelectAll - I make sure that I manually select the sketch entities before creating the SketchBlockDefinition.

          The other difference is that my code is in a VBA macro. Hopefully that won't be the issue though.

          Try manually selecting the sketch entities and see if that makes a difference. If it does, then you'll have to programmatically select them instead of doing a SelectAll.