AnsweredAssumed Answered

Create ordinate dimensions via API

Question asked by Jana Stahn on Nov 18, 2016
Latest reply on Nov 18, 2016 by Ivana Kolin

I have successfully built an add-in that creates a linear dimension via API in a drawing document. But now I am struggling to create ordinate dimensions with the same method.

 

Here is the scenario:

- I have a part document which contains a sketch with the name "special_sketch". This special_sketch contains only two parallel sketch lines, nothing more.

- I have a drawing document which has a view of the part document described above. When this drawing document is open, I start the add-in. This is what the add-in does:

 

step 1: Store the drawing document in the variable "drwDoc" (of type IModelDoc2) and the view in the variable "selView" (of type IView).

step 2: Find the referenced document of the view (which is the abovementioned part).

step 3: In this part, find the special_sketch by traversing the feature tree.

step 4: Extract and store the two sketch lines of the special_sketch in the variables "line1" and "line2" (of type ISketchLine or ISketchSegment).

step 5: Here is the part that creates the dimension. This is the C# code:

 

 

          drwDoc.SelectionManager.SuspendSelectionList();

          SelectData selData = drwDoc.SelectionManager.CreateSelectData();

          selData.View = selView as View;

          drwDoc.SelectionManager.AddSelectionListObject(line1, selData);

          drwDoc.SelectionManager.AddSelectionListObject(line2, selData);

 

          drwDoc.AddDimension2(0, 0, 0);

 

          drwDoc.SelectionManager.ResumeSelectionList();

 

 

This works; the linear dimension is created.

Note: I am using the API version of 2013, that's why I have IModelDoc2.AddDimension2 instead of IModelDoc2.Extension.AddDimension.

 

Now I replaced AddDimension2 by ModelDoc2.Extension.AddOrdinateDimension. The steps 1 to 4 stay the same. This is the code for step 5:

 

 

          drwDoc.SelectionManager.SuspendSelectionList();

          SelectData selData = drwDoc.SelectionManager.CreateSelectData();

          selData.View = selView as View;

          drwDoc.SelectionManager.AddSelectionListObject(line1, selData);

          drwDoc.SelectionManager.AddSelectionListObject(line2, selData);

 

          int retval = drwDoc.Extension.AddOrdinateDimension(1, 0, 0, 0); // always returns 0, which means "success"

          drwDoc.SetPickMode(); // to end the ordinate dimensioning mode

 

          drwDoc.SelectionManager.ResumeSelectionList();

 

 

And it does not work, i.e. no new dimension is generated. Still, I always get the return value 0 (which means "success"). So how do I do this?

 

I tried a few things but they all did not help me solve the problem...

 

- Instead of SuspendSelectionList, AddSelectionListObject and ResumeSelectionList I used ISketchSegment.Select4 (line1 with false, line2 with true). But again, it worked alright for AddDimension2 but not for AddOrdinateDimension.

- Changing the first argument in AddOrdinateDimension (tried 0,1, 2, 3, 4) did not help.

- First selecting line1, then calling AddOrdinateDimension, then selecting line2 did not help.

- First calling AddOrdinateDimension, then selecting the two lines did not help.

- Instead of programmatically selecting, I selected the two lines by hand and then ran the add-in. THEN IT WORKED.

 

Any hints are appreciated!

Outcomes