Changing balloon shape by BOM item

Changing balloon shape by BOM item

frederico.prado
Explorer Explorer
355 Views
2 Replies
Message 1 of 3

Changing balloon shape by BOM item

frederico.prado
Explorer
Explorer

Greetings, 

 

I'm struggling with this problem a while, I need a code that can change the shape only of the balloons with the item value is greater than 100.

 

We use to work with two part lists at the same drawing , one for purchased itens (BOM Item number 1 to 99), and another for the manufactured items (BOM Item number 101 to 299), for the first one, we use round shape balloon, and for the second, we use hexagonal shape.

 

I know this sounds useless because you can tell the difference by the number, but this is the way my company work.

 

I’m messing with this code, but I can figure out the line to change only the balloons greater than 100, this one change all balloons … and I have zero knowledge about programing.

 

Dim oDrawDoc As DrawingDocument

oDrawDoc = ThisApplication.ActiveDocument



Dim oStyles As DrawingStylesManager

oStyles = oDrawDoc.StylesManager



Dim oSheet As Sheet

Dim oBalloon As Balloon



For Each oSheet In oDrawDoc.Sheets

            For Each oBalloon In oSheet.Balloons

                        oBalloon.Style = oStyles.BalloonStyles.Item("Proprio")

            Next

Next

 

Thank you!

0 Likes
Accepted solutions (1)
356 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @frederico.prado.  If I am understanding the situation correctly, then I think that the code below may help you accomplish your goal.  Or if not, at least yet you much closer to your goal.  Let me know how this works out for you.  Keep in mind that the BalloonStyle being looked for and used by the rule will need to be local to the document, not only existing within the global styles library.  If this is sometimes not the case, the rule may need to be expanded slightly to attempt to copy the style down to the document from the library before attempting to use it.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oBStyles As BalloonStylesEnumerator = oDDoc.StylesManager.BalloonStyles
'specify BalloonStyle to use for 100-199 Item Numbered Balloons
Dim oBStyle As BalloonStyle = oBStyles.Item("Proprio")
For Each oSheet As Sheet In oDDoc.Sheets
	If oSheet.Balloons.Count = 0 Then Continue For
	For Each oBl As Balloon In oSheet.Balloons
		Dim oItemNum As String = oBl.BalloonValueSets.Item(1).ItemNumber
		If CInt(oItemNum) >= 100 Then
			Dim oBType As BalloonTypeEnum
			Dim oBTypeData As Object = Nothing
			oBl.GetBalloonType(oBType, oBTypeData)
			If oBType <> BalloonTypeEnum.kHexagonBalloonType Then
				oBl.SetBalloonType(BalloonTypeEnum.kHexagonBalloonType)
			End If
		End If
	Next
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

frederico.prado
Explorer
Explorer

Dear @WCrihfield , the code works perfectly!

 

Thank you so much!

 

0 Likes