iLogic - Need to run CenterText twice to Center Dimensions

iLogic - Need to run CenterText twice to Center Dimensions

Anonymous
Not applicable
1,169 Views
6 Replies
Message 1 of 7

iLogic - Need to run CenterText twice to Center Dimensions

Anonymous
Not applicable

Hello,

 

I am having an interesting issue when it comes to automating my Center Dimension Texts on my drawings. Right now I am trying to incorporate this line of code into my iLogic rules:

 

 

   Dim oDrawDoc As DrawingDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet Dim oDrawingDim As DrawingDimension For Each oDrawingDim In oSheet.DrawingDimensions If TypeOf oDrawingDim Is LinearGeneralDimension Or _ TypeOf oDrawingDim Is AngularGeneralDimension Then Call oDrawingDim.CenterText End If Next

 

Here is a screenshot of what it looks like after I have run the rule.

CenterDimensions.PNG

 

I do not get any errors with this, but it just doesn't exactly center it, I can tell it semi works, because I have moved dimensions crazily and run the rule and it pushes it to this location. The weird thing is that we have a plug-in that does this using this code:

 

            Dim oDoc As Inventor.DrawingDocument = Nothing
            oDoc = g_inventorApplication.ActiveDocument
            Dim oDrawingView As Inventor.DrawingView = Nothing
            Dim oSheet As Inventor.Sheet
            oSheet = oDoc.ActiveSheet

            For Each oDrawingDim In oSheet.DrawingDimensions
                If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
                    Call oDrawingDim.CenterText
                End If
            Next

Now when I click this button once, it does nothing. However, if I click it TWICE it works:

CenterDimensionWorks.PNG

 

It is kind of peculiar why I have to run this button twice to get it to work. But, I thought maybe if I just placed the code twice in the iLogic rule, maybe it would simulate the same thing. It did not end up working that way. Does anyone have any suggestions? Or maybe there is another way to code this same function that I can try.

 

0 Likes
Accepted solutions (2)
1,170 Views
6 Replies
Replies (6)
Message 2 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide reproducible steps and Inventor files to investigate? please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 7

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Hi,

 

I have seen this as normal behavior since inventor 2012.

 

So I think this is a smaller inventor API bug.

 

solution:

 

For Each oDrawingDim In oSheet.DrawingDimensions
                If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
                    	Call oDrawingDim.CenterText ' 1x
			Call oDrawingDim.CenterText ' 2x
                End If
            Next

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 7

rayessle
Advocate
Advocate
Accepted solution

I was having the same problem. See this post here

https://forums.autodesk.com/t5/inventor-customization/why-does-this-rule-only-work-the-second-time-y...

I think it has to do with the fact that inventor has not updated the document prior to you trying to centre the text so it doesn't know the dimensions are off centre. when you run the rule the first time it updates the document so the second time it knows the dimensions are off centre.

 

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

Thanks for the response. This ultimately is what I did to get it to work.

 

For whatever reason it still doesn't work without the two executes, but it doesn't work at all if this code runs before the update. Here is what I needed to adjust:

 

    oDrawDoc.Update

   For Each oDrawingDim In oSheet.DrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or _
           TypeOf oDrawingDim Is AngularGeneralDimension Then
            Call oDrawingDim.CenterText
            Call oDrawingDim.CenterText
        End If
    Next
Message 6 of 7

filippo.costantin3HZMT
Advocate
Advocate

Hi, 

I have similar problem with manage dimension with ilogic. 

I use a rule like yours, but if I have the configuration o drawing like:iD1.PNG

When I run the rules, the dimensions are overlapping.

iD2.PNG

How can resolve it?

 

0 Likes
Message 7 of 7

insomnix
Advocate
Advocate

I had to have two update's, one placed between the two center text lines, for it to work properly in my code. For anyone else who is still having issues after trying the above code:

   oDrawDoc.Update
   For Each oDrawingDim In oSheet.DrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or _
           TypeOf oDrawingDim Is AngularGeneralDimension Then
            Call oDrawingDim.CenterText
            oDrawDoc.Update
            Call oDrawingDim.CenterText
        End If
    Next

 Thanks to those responding on this thread, you pointed me in the right direction.

0 Likes