Ilogic Center and Arrange dimensions - Doubt?

Ilogic Center and Arrange dimensions - Doubt?

cinemediatamil
Participant Participant
285 Views
7 Replies
Message 1 of 8

Ilogic Center and Arrange dimensions - Doubt?

cinemediatamil
Participant
Participant
'This iLogic Code Centre's and Arranges Dimensions
'Code by @ClintBrown3D 'Originally posted at https://clintbrown.co.uk/ilogic-centre-arrange-dimensions

On Error GoTo ClintBrown3D
'Code to Centre Dimensions - Adapted from the Inevntor API Sample by @ClintBrown3D
	' a reference to the active drawing document
    Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument

    ' a reference to the active sheet & dimension
    Dim oSheet As Sheet 
    oSheet = oDoc.ActiveSheet
    Dim oDrawingDim As DrawingDimension

    ' Iterate over all dimensions in the drawing and center them if they are linear or angular.
    For Each oDrawingDim In oSheet.DrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
            Call oDrawingDim.CenterText
        End If
    Next
'--------------------------------------------------------------------------------------------------------------------	
'Code to Centre Dimensions - Adapted from https://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html
' Get the active document, assuming it is a drawing.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

    ' Get the collection of dimensions on the active sheet.
    Dim oDimensions As DrawingDimensions
    oDimensions = oDrawDoc.ActiveSheet.DrawingDimensions
	
	    ' Get a reference to the select set and clear it.
    Dim oSelectSet As SelectSet
    oSelectSet = oDrawDoc.SelectSet
    oSelectSet.Clear

    ' Add each dimension to the select set to select them.
    Dim oDrawDim As DrawingDimension
    For Each oDrawDim In oDimensions
        oSelectSet.Select(oDrawDim)
    Next
    	
	Call ThisApplication.CommandManager.ControlDefinitions.Item("DrawingArrangeDimensionsCmd").Execute
	
Return
ClintBrown3D :
MessageBox.Show("We've encountered a mystery", "Unofficial Inventor", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)

code -  iLogic – Centre & Arrange Dimensions – Clint Brown

"The above code is working well; it automatically corrects the dimension arrangement in all views. However, I want to apply it specifically to a selected view. For example, I would like to run the rule, select the view, center it, and arrange the dimensions. Could you please guide me on how to do this?"

 

0 Likes
Accepted solutions (1)
286 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @cinemediatamil.  The most challenging part of your request is determining which dimensions belong to the one selected view.  The collection of all drawing dimensions belong to the Sheet, not to any drawing view.  And the 'Parent' of every drawing dimension is the Sheet, not a drawing view.  So, there is no 'direct' link between each drawing dimension and what drawing view it is supposed to be associated with, that is easy for us to determine by code.  I actually created a 'Idea' post in the Inventor Ideas forum (Link Here) about this issue, because many people have wanted that association to be simpler to determine for many years.  Another challenge involved is how many 'sub-types' of dimensions there are, with each sub-type having different properties &/or methods available to it, which are specific to that type of dimension.  In the example below, I am using one of those strategies that is not 100% reliable to determine if the text of each dimension is located within the bounds of the specified drawing view.  

Sub Main
	'get Inventor Application
	Dim oInvApp As Inventor.Application = ThisApplication
	'get active document and try to Cast it to a DrawingDocument Type
	Dim oDDoc As DrawingDocument = TryCast(oInvApp.ActiveDocument, Inventor.DrawingDocument)
	'if that did not work, it was wrong document type, so exit rule
	If oDDoc Is Nothing Then Return
	'prompt user to pick a drawing view object
	Dim oView As DrawingView = oInvApp.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View.")
	'if nothing was selected, then exit the rule
	If oView Is Nothing Then Exit Sub
	'get the Sheet that the view is on
	Dim oSheet As Inventor.Sheet = oView.Parent
	'get all the dimensions on this sheet
	Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
	Dim oViewDims As Inventor.ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection()
	For Each oDDim As DrawingDimension In oDDims
		If Not DimIsInView(oView, oDDim) Then Continue For
		If TypeOf oDDim Is LinearGeneralDimension Or TypeOf oDDim Is AngularGeneralDimension Then
            Try
				oDDim.CenterText()
			Catch
				'what to do if that caused an exception
			End Try
        End If
		oViewDims.Add(oDDim)
	Next
	oDDoc.SelectSet.SelectMultiple(oViewDims)
	oInvApp.CommandManager.ControlDefinitions.Item("DrawingArrangeDimensionsCmd").Execute()
	
End Sub

Function DimIsInView(oDView As DrawingView, oDim As DrawingDimension) As Boolean
	Dim oBox2d As Inventor.Box2d = ThisApplication.TransientGeometry.CreateBox2d()
	oBox2d.PutBoxData({oDView.Left, oDView.Top - oDView.Height }, {oDView.Left + oDView.Width, oDView.Top})
	If oBox2d.Contains(oDim.Text.Origin) Then Return True
	Return False
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

cinemediatamil
Participant
Participant

This i logic is not working!

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Hi @cinemediatamil.  Can you please explain in which ways it is not working?  What do you see happen when you run the rule?  Does it prompt you to pick a drawing view?  Do any dimensions or the text of any dimensions move at all?  Was there any error message shown?  If it showed an error message, then what did the error message say on its 'More Info' tab, because that can sometimes be helpful.

 

I mentioned that the method I was using there for determining if a drawing dimension was associated with a specific drawing view on the active sheet was by checking if the text of the dimension was within the bounds of the specified drawing view, and if not, it does not find that association.  If that is not always the case for you, then a different method may be needed for determining the association between each dimension and one of the specific drawing views on the sheet.  The Link to an Inventor Idea post that I provided in my first response has a text file attached to it containing a custom Function which lets us specify a drawing dimension object, then it attempts to figure out which drawing view it is associated with by way of 'GeometryIntent' connections, and if a view is found, it returns that view.  You may be able to integrate that custom Function into your rule, then modify how the rule works to best utilize that resource...but even if you do, there is still no guarantees it will work 100% of the time either.

 

Attached is a text file containing the code for another example iLogic rule you can try out.  It uses different methods for determining the association between each dimension and any view.  I tried to include a lot of comments, so you can read through it and understand what each line of code is attempting to do.

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

cinemediatamil
Participant
Participant

Hi, Iam run the rule no error happening, iam pick the view and dimension is arranged but this affect other views also . Iam pick the single view but other views also dimensions arranged.

 

My need is pick the view that only Dimensions arranged.

0 Likes
Message 6 of 8

cinemediatamil
Participant
Participant

I tried but I don't know why not working could please try your inventor in run the i logic rule in drawing arrangement and send the video or image it's help full

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor
Accepted solution

I never need to use something like this, but I did open one of my drawings which had multiple views on one sheet, moved the dimensions within one of its views around to obviously bad locations, copied my code into a rule within that drawing, then ran it.  I picked the view with the messed-up dimensions, then it showed me an error message saying that the 'Intent' parameter of the "DrawingDocumentUtil.GetDrawingView" method could not be empty/Nothing.  That was odd, because I already had a line of code above that point checking if the List had any values in it, and if not to skip to the next dimension.  So, I added an extra line of code just above that line of code like the following:

If oGI Is Nothing Then Continue For

That seemed to get rid of the error message, allowing the rule to run to completion.  It only visibly effected the one view that I chose.  But I did not intentionally mess-up the dimensions in all the other views, so maybe that was the catch.  So, then I intentionally messed up most of the dimensions in all the other views, then tested again.  It still seemed to only effect the one view that I picked.

I am talking about the code that I just posted in the text file above today, not either of the earlier ones.  No time for making videos, barely enough time to do the testing and reply.  Got a lot of other stuff going on at work right now.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

cinemediatamil
Participant
Participant

Thanks for replying and helping for me and also it's helpfull for Future users.  working Good

 

Regards 

 

Vijay Balakrishnan 

0 Likes