Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Arranging Dimensions in Drawing Sheet

8 REPLIES 8
Reply
Message 1 of 9
sanjeev_sachan
295 Views, 8 Replies

Arranging Dimensions in Drawing Sheet

Good Afternoon,

 

I have created a drawing sheet using C# , I also put dimensions in my sheet using the Inventor apis 

All the things works perfectly except the arrangement 

 

Below is the attached photo of my drawing sheet and the arrangement of the same which look mess and finding it difficulty to see the view and reading 

sanjeev_sachan_0-1695724263545.png

I want the reading should look like this , separated and clearly visible 

sanjeev_sachan_1-1695725129156.png

 

I have attached code below in which I have shown my method

Can someone guide me please as I have tried many many ways to do this but failed

Now with lot of hope I am writing this forum


The code snippet shown below uses "Retrieve"  method to get all the dimension


DrawingView view1 = drawingDoc.ActiveSheet.DrawingViews[1];
drawingDoc.ActiveSheet.DrawingDimensions.GeneralDimensions.Retrieve(view1);

After getting all the dimensions I have run the another code for deleting similar dimension , and print only the dimensions which comes one time in Drawing sheet

 

foreach (GeneralDimension dimension in drawingDoc.ActiveSheet.DrawingDimensions.GeneralDimensions)
{
///MYCODE FOR DELETING THE ANGULAR AND REPETATING DIMENSIONS///
}

After doing this I have use another code snippet shown below to get arrange the dimension in proper view 
but its not arranging properly

 

ObjectCollection arrange_dimen = inventor_app.TransientObjects.CreateObjectCollection();
foreach (GeneralDimension dimen in drawingDoc.ActiveSheet.DrawingDimensions.GeneralDimensions) 
{
if (dimen.Type == ObjectTypeEnum.kLinearGeneralDimensionObject)
{
arrange_dimen.Add(dimen);
}
}
if (arrange_dimen.Count > 1)
{
drawingDoc.ActiveSheet.DrawingDimensions.Arrange(arrange_dimen);
}

 

 

Can someone guide me through this , how can I do this 
I don't want to do major changes in my code just want to do this changes

 

Thankyou in Advance

8 REPLIES 8
Message 2 of 9

Can you provide a sample drawing and the 'arrange dimensions' function from your code?

 

Here's an example of what I used, and I got the results that I expected - i.e. the same as if I used the "Arrange Dimensions" feature of the right click context menu.

Sub ArrangeDims()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim Dims As ObjectCollection
Set Dims = ThisApplication.TransientObjects.CreateObjectCollection

Dim oSS As SelectSet
Set oSS = oDoc.SelectSet

Dim oObj As Object

For Each oObj In oSS
    If oObj.Type = kLinearGeneralDimensionObject Then
        Dims.Add oObj
    End If
Next oObj

oDoc.ActiveSheet.DrawingDimensions.Arrange Dims

End Sub

 

Just double-check that your dimension style is set up correctly. You'll need values for "D" and "E" to be large enough to allow the dimensions to space out correctly.

 

gerrardhickson_0-1695781895841.png

 

Personally, I don't like the way 'Arrange Dimensions' works - it would be better if you could create multiple subsets of your dimensions, and use 'Arrange Dimensions' on those, so you still have some control. For each one set, you'll need to manually set a dimension offset so they don't stack on top of one another.

 

I hope that helps.

 

 

Message 3 of 9

This is my arrange dimension code @gerrardhickson 

 

 

ObjectCollection arrange_dimen = inventor_app.TransientObjects.CreateObjectCollection();
foreach (LinearGeneralDimension dimen in drawingDoc.ActiveSheet.DrawingDimensions.GeneralDimensions) // This code is used to arrange the dimension in the drawing sheet
{
if (dimen.Type == ObjectTypeEnum.kLinearGeneralDimensionObject)
{
arrange_dimen.Add(dimen);
}
}
if (arrange_dimen.Count > 1)
{
drawingDoc.ActiveSheet.DrawingDimensions.Arrange(arrange_dimen);
}

 

And for getting the dimension from the sheet I am using retrieve method:

DrawingView view1 = drawingDoc.ActiveSheet.DrawingViews[1];
drawingDoc.ActiveSheet.DrawingDimensions.GeneralDimensions.Retrieve(view1);

 

 

What I am doing @gerrardhickson I am using Retrieve method to get all the dimension , after getting all the dimension I am deleting the repeating dimension and showing the dimension only one time in sheet

 

and after all the process I am using Arrange dimension process as shown above to arrange the dimension

Is this enough @gerrardhickson or should I do something else

Hoping for best solution

 

Message 4 of 9

Your code looks OK. Have you checked your drawing styles? Can you provide a sample drawing?

Message 5 of 9

How can I make subsets of dimensions, as I am using Retrieve method and getting all the dimension at once , so how can I make subsets of dimensions.
Can you please guide me through this , as I am not aware about making subsets of dimensions

Message 6 of 9

I have attached the drawing , some parts are not correct but my aim is to just show you the dimensions @gerrardhickson 

Message 7 of 9

Ok - as I suspected, your problem is your dimension styles. You need to change your dimension styles for values C, D and E (as per my earlier image) to find values that give you the best result.

 

HOWEVER.

Because you have horizontal text for all dimensions, this means that your spacing for dimensions on the left and right of the drawing view, need more space than the dimensions on the top and bottom of your view. If you have one drawing style, then you will choose values that make the left and right dimensions look OK, but the top and bottom will be spaced out too far.

 

To solve this. I created 2 dimension styles - one for left and right dimensions ("Vert Dimensions") and one for the top and bottom dimensions ("Horiz Dimensions") and set different spacing values for these styles so they look neat.

Then, using code, we test for whether the dimension is a vertical or horizontal dimension, assign it to the correct style and arrange it appropriately.

 

I've attached the file, but here are the dimension styles used for reference:

gerrardhickson_0-1695810921724.png

gerrardhickson_1-1695810929297.png

 

And here is the code that I used to assign them to styles and arrange:

Sub ArrangeDims()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim VertDims As ObjectCollection
Set VertDims = ThisApplication.TransientObjects.CreateObjectCollection
Dim HorizDims As ObjectCollection
Set HorizDims = ThisApplication.TransientObjects.CreateObjectCollection

Dim oSS As SelectSet
Set oSS = oDoc.SelectSet

Dim oObj As Object
Dim oDim As DrawingDimension

Dim dAng As Double
Dim sAng As String

Dim VertDimStyle As DimensionStyle
Dim HorizDimStyle As DimensionStyle
Set VertDimStyle = oDoc.StylesManager.DimensionStyles("Vert Dimensions")
Set HorizDimStyle = oDoc.StylesManager.DimensionStyles("Horiz Dimensions")

Dim DimPos As String

For Each oDim In oDoc.ActiveSheet.DrawingDimensions
    
    ' RESET OUR FLAGS
    sAng = ""
    dAng = 1
    
    ' CALCULATE THE ORIENTATION OF THE DIMENSION.
    If oDim.IntentOne.PointOnSheet.x = oDim.IntentTwo.PointOnSheet.x Then
        sAng = "Vert"
    ElseIf oDim.IntentOne.PointOnSheet.y = oDim.IntentTwo.PointOnSheet.y Then
        sAng = "Horiz"
    Else
        dAng = Abs(oDim.IntentOne.PointOnSheet.y - oDim.IntentTwo.PointOnSheet.y) / Abs(oDim.IntentOne.PointOnSheet.x - oDim.IntentTwo.PointOnSheet.x)
    End If
    
    
    ' ADD THE DIMENSION TO THE APPROPRIATE OBJECTCOLLECTION
    If sAng = "Vert" Or dAng > 1 Then
        VertDims.Add oDim
        oDim.Style = VertDimStyle
    ElseIf sAng = "Horiz" Or dAng < 1 Then
        HorizDims.Add oDim
        oDim.Style = HorizDimStyle
    End If
    
Next oDim

oDoc.ActiveSheet.DrawingDimensions.Arrange VertDims
oDoc.ActiveSheet.DrawingDimensions.Arrange HorizDims

End Sub

 

I would also recommend adding some code to help place the dimensions on the appropriate side of the drawing view - some of your dimensions reach almost the full way across the drawing view which is untidy. You can move dimensions by editing the X and Y values of the Dimension.Text.Origin property. Do this before you arrange the dimensions.

 

Hope that helps.

Message 8 of 9

First of all thankyou so much for replying , and giving me solution
I will try by my side and once done I will inform you
Message 9 of 9

Good Morning @gerrardhickson 
Last doubt , please help me with one thing
I have change your VB code in C# , but getting error as CONTENT ERROR I will show you

The code which I have change is:

if (oDim.IntentOne.PointOnSheet.x == oDim.IntentTwo.PointOnSheet.x)
{
sAng = "Vert";
}
else if (oDim.IntentOne.PointOnSheet.y == oDim.IntentTwo.PointOnSheet.y)
{
sAng = "Horiz";
}
else
{
dAng = Math.Abs(oDim.IntentOne.PointOnSheet.y - oDim.IntentTwo.PointOnSheet.y) / Math.Abs(oDim.IntentOne.PointOnSheet.x - oDim.IntentTwo.PointOnSheet.x);
}
if (sAng == "Vert" || dAng > 1)
{
VertDim.Add(oDim);
}
else if (sAng == "Horiz" || dAng < 1)
{
HoriDim.Add(oDim);
}

 

And the error is :


1. Severity Code Description Project File Line Suppression State
Error CS1061 'DrawingDimension' does not contain a definition for 'IntentOne' and no accessible extension method 'IntentOne' accepting a first argument of type 'DrawingDimension' could be found (are you missing a using directive or an assembly reference?)

2. Severity Code Description Project File Line Suppression State
Error CS1061 'DrawingDimension' does not contain a definition for 'IntentTwo' and no accessible extension method 'IntentTwo' accepting a first argument of type 'DrawingDimension' could be found (are you missing a using directive or an assembly reference?) 

Can you please guide me such that I can perform my work
Just help me last time and provide me your precious time 

 

Thankyou @gerrardhickson 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report