Exclude dimensions from arrange rule

Exclude dimensions from arrange rule

Tom_Servo
Advocate Advocate
832 Views
11 Replies
Message 1 of 12

Exclude dimensions from arrange rule

Tom_Servo
Advocate
Advocate

I'm using an arrange rule (see below) but I want the ability to exclude specific dimensions. 

I'm also using Nifty Attributes / Attribute Helper and I imagine I would use names like these:

Attribute Set = arrange

Attribute Name = arrange

Value = no

 

 

Would anyone be able to help me out?

 

 

 

 

Arrange rule

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Dim oDrawingDim As DrawingDimension
Dim oDrawingDims As DrawingDimensions
Dim oDimsToBeArranged As ObjectCollection

'[Dimensions in all Views and on all Sheets
oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection
For Each oSheet In oDoc.Sheets
    oDrawingDimensions=oSheet.DrawingDimensions
    For Each oDrawingDim In oDrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
           oDrawingDim.CenterText
           oDimsToBeArranged.Add(oDrawingDim)
        End If
    Next
Next    
oDrawingDimensions.Arrange(oDimsToBeArranged)
']

 

833 Views
11 Replies
Replies (11)
Message 2 of 12

bradeneuropeArthur
Mentor
Mentor
Why not using a selectionset?

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

0 Likes
Message 3 of 12

berry.lejeune
Advocate
Advocate

@Tom_Servo 

I didn't even know this was possible. No idea how to change your code. 

But I hope you don't mind me using this code also.

Message 4 of 12

Tom_Servo
Advocate
Advocate

Glad I could share. 


It would be cool if more people shared awesome rules that they made.

Message 5 of 12

WCrihfield
Mentor
Mentor

Hi @Tom_Servo.  I still think that simply selecting them manually just before running the rule, then using the drawing document's SelectSet to get them to a variable, as @bradeneuropeArthur was suggesting would likely be much simpler for you, but here is a simple example, using the names & value you suggesteds for AttributeSet, Attribute, & value.  This is rather condensed, but you could expand it out, if you wanted to.

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oDimsToBeArranged As ObjectCollection
oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection
For Each oSheet As Sheet In oDoc.Sheets
	Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
	If oDDims.Count = 0 Then Continue For 'to avoid potential error
	For Each oDDim As DrawingDimension In oDDims
		Try
			If oDDim.AttributeSets.Item("arrange").Item("arrange").Value = "no" Then
				Continue For 'skip to next dimension, without doing anything with this one
			Else
				oDDim.CenterText
				oDimsToBeArranged.Add(oDDim)
			End If
		Catch
		End Try
	Next
	Try : oDDims.Arrange(oDimsToBeArranged) : Catch : End Try
Next

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 6 of 12

Tom_Servo
Advocate
Advocate

I'm open to different approaches. 
What would the selection set look like? 


0 Likes
Message 7 of 12

WCrihfield
Mentor
Mentor

Every Document Type object (including PartDocument, AssemblyDocument, DrawingDocument, and others) has a property called SelectSet (Link1, Link2), which will contain any objects that you have selected within that document.  Similarly to how you can often manually select one or more objects manually prior to starting a command for doing something with those those objects, we can use this SelectSet object to obtain whatever objects we may have selected, when we start an iLogic rule, so that the rule can do something with those objects.  It is not always super simple to use though.  Due to the vast variety of objects that it can contain, you often have to first identify what Type of objects are in the collection, before attempting to start doing something with them.  You can also add new objects into it from within the rule, if you need to, by using either its Select method, or its SelectMultiple method.

Below is a fairly simple example which looks in the drawing's SelectSet for the dimensions you want to arrange.  I could be wrong, but I think all the dimensions may need to be on the same sheet of the drawing for this to work.

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
If oDoc.SelectSet.Count = 0 Then Exit Sub
Dim oDimsToBeArranged As ObjectCollection
oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection
For Each oObj As Object In oDoc.SelectSet
	If TypeOf oObj Is DrawingDimension Then oDimsToBeArranged.Add(oObj)
Next
For Each oDim As DrawingDimension In oDimsToBeArranged
	Try : oDim.CenterText : Catch : End Try
Next
Try 'I think hey may all need to be on the same sheet
	oDoc.ActiveSheet.DrawingDimensions.Arrange(oDimsToBeArranged)
Catch
End Try

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 12

Tom_Servo
Advocate
Advocate

@WCrihfield 

I tried this code that you posted:

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oDimsToBeArranged As ObjectCollection
oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection
For Each oSheet As Sheet In oDoc.Sheets
	Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
	If oDDims.Count = 0 Then Continue For 'to avoid potential error
	For Each oDDim As DrawingDimension In oDDims
		Try
			If oDDim.AttributeSets.Item("arrange").Item("arrange").Value = "no" Then
				Continue For 'skip to next dimension, without doing anything with this one
			Else
				oDDim.CenterText
				oDimsToBeArranged.Add(oDDim)
			End If
		Catch
		End Try
	Next
	Try : oDDims.Arrange(oDimsToBeArranged) : Catch : End Try
Next

 

It does exclude the dimensions with 'arrange', 'arrange', 'no, however it doesn't seem to arrange any of the other dimensions. 

 

I copied it directly to a rule, is there anything else you could think of that I might be doing wrong?
Was it arranging your dimensions?

 

-TS

0 Likes
Message 9 of 12

WCrihfield
Mentor
Mentor

I mentioned this in another post, but I suspect that all of the dimensions in the ObjectCollection may need to be on the same Sheet of the drawing as the DrawingDimensions object that you use the Arrange method from, because the DrawingDimensions collection object that you use the Arrange method from, is localized to a specific Sheet object.  The dimensions within the ObjectCollection can be associated with multiple different views on the sheet, but I think they at least need to all be on that same sheet for that method to work.  This is just my theory at this point, because I do not see this mentioned in any online help documentation, but it makes logical sense to me.  So, I suspect that you would have to process the dimensions one sheet at a time, instead of a whole drawing document at a time, if they span multiple sheets.

 

Edit:  I am not 100% sure why that code is not working correctly for you, because it does seem to be just processing one sheet at a time.  I think this may be due to the fact that I am creating the ObjectCollection before the loop starts, and the loop keeps adding more to the collection from each sheet.  We probably need to 'Clear' the collection before processing each sheet, to make sure there are none in it from previous sheets.

Try inserting this following line:

oDimsToBeArranged.Clear

...just inside the loop of each Sheet, to ensure the collection gets cleared out before attempting to process each sheet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 12

Tom_Servo
Advocate
Advocate

My drawing only has one sheet but I added the oDimsToBeArranged.Clear anyway:

Tom_Servo_0-1673456554239.png

But still no change. 

I did notice that if I create an attribute 'arrange', 'arrange', 'yes', then it will arrange that dimension but I need it to by default arrange all dimensions except those that have an attribute 'arrange', 'arrange', 'no'.

 

Here's what my dimension attributes look like:

Tom_Servo_1-1673456876345.png

 

0 Likes
Message 11 of 12

WCrihfield
Mentor
Mentor

Hi @Tom_Servo.  I just copied that last code into a rule within a single sheet drawing, which had around 16+ dimensions on it, moved the dims around, so they were not centered, and not arranged nicely.  I first commented out the part of the code which was looking for the dimensions with those attributes, then ran the rule.  It almost instantly centered and arranged all of the dimensions that it could (there were a few radius dims in there too).  So, I'm not real sure why it may not be working for you.  If you look at the documentation for that Arrange method, is says that it can contain DrawingDimension & ChainDimensionSet type objects, but then goes on to say that it will not work on individual members of an OrdinateDimensionSet, members of a BaselineDimensionSet, or members of a ChainDimensionSet.  So, if some of your dimensions were created as members of those types of sets, and you attempted to put each individual member object into the ObjectCollection, that may be what's causing problems.  I almost never use BaselineDimensionsSets or ChainDimensionSets, but do use OrdinateDimensionSets somewhat often, but did not have any in the drawing I tested on.  So, you may need to filter the dimension objects further, to avoid these potential issues.  Fortunately, each of those DimensionSet type objects has their own Arrange type methods that you could look into.  It might require expanding the code a bit, to make it more robust though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 12

WCrihfield
Mentor
Mentor

Here is some expanded code you can play around with.  This one first looks for any dimension 'sets' that may be present on the sheet.  If found, attempts to use their own 'arrange' related method, then adds all of their members to a 'List', so we know which individual dimensions to avoid later.  Then it looks at the individual GeneralDimensions.  If it is in the list, it will skip it.  Then it checks for your attribute value, inside of its own Try...Catch block.  Then it tries to use the CenterText method, which is only available to certain sub-types of general dimensions, which is also in its own Try...Catch block.  Then at the end, is still our main Arrange method, for all those individual dimensions, also in its own Try block.  You may not like all of those different arrange type methods of each type of set, so you could just comment out any line that is not working the way you want.  Just trying to expand on the possibilities.  We could have also expanded the code down into each of the sub-types of general dimensions with a bit more code.

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oDimsToBeArranged As ObjectCollection
oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection
For Each oSheet As Sheet In oDoc.Sheets
	Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
	If oDDims.Count = 0 Then Continue For 'to avoid potential error
	oDimsToBeArranged.Clear
	Dim oSetMemberDimsToAvoid As New List(Of DrawingDimension)
	If oDDims.BaselineDimensionSets.Count > 0 Then
		For Each oBDS As BaselineDimensionSet In oDDims.BaselineDimensionSets
			oBDS.ArrangeText
			For Each oMember In oBDS.Members : oSetMemberDimsToAvoid.Add(oMember) : Next
		Next
	End If
	If oDDims.ChainDimensionSets.Count > 0 Then
		For Each oCDS As ChainDimensionSet In oDDims.ChainDimensionSets
			oCDS.Arrange(oCDS.Members.Item(1)) 'align other members to first member
			For Each oMember In oCDS.Members : oSetMemberDimsToAvoid.Add(oMember) : Next
		Next
	End If
	If oDDims.OrdinateDimensionSets.Count > 0 Then
		For Each oODS As OrdinateDimensionSet In oDDims.OrdinateDimensionSets
			oODS.AlignMembers = True
			For Each oMember In oODS.Members : oSetMemberDimsToAvoid.Add(oMember) : Next
		Next
	End If
	If oDDims.GeneralDimensions.Count > 0 Then
		For Each oGDim As GeneralDimension In oDDims.GeneralDimensions
			If oSetMemberDimsToAvoid.Contains(oGDim) Then Continue For
			'continue code to center & arrange them
			Try : If oGDim.AttributeSets.Item("arrange").Item("arrange").Value = "no" Then Continue For
			Catch : End Try
			Try : oGDim.CenterText : Catch : End Try
			oDimsToBeArranged.Add(oDDim)
		Next
	End If
	Try : oDDims.Arrange(oDimsToBeArranged) : Catch : End Try
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes