Ilogic program to override the value of Balloon.

Ilogic program to override the value of Balloon.

naveedmX3N25
Contributor Contributor
807 Views
9 Replies
Message 1 of 10

Ilogic program to override the value of Balloon.

naveedmX3N25
Contributor
Contributor

Hello,

 

What is wrong with my code to change the override value of my balloon?

 

' iLogic rule to change the balloon value by asking the user to enter a value

Dim valueEntered As String

' Prompt the user to enter a value
valueEntered = InputBox("Enter the value for the balloon:", "Balloon Value")

' Check if the user entered a value
If valueEntered <> "" Then
    ' Update the balloon value with the user-entered value
	 ThisDrawing.Sheet.Balloons.ManagedItem.Name.Equals = valueEntered
Else
    MsgBox("No value entered. Balloon value remains unchanged.")
End If

naveedmX3N25_0-1709745348977.png

Thanks in advance.

0 Likes
Accepted solutions (3)
808 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Hi @naveedmX3N25.  In that short code there are multiple issues.  First, it is not specifying which specific sheet to access.  Second, it is not specifying which Balloon to access.  Third, it is not accessing the correct property of that Balloon.  Balloons do not have names, but they do have a BalloonValueSets collection, because we can chain multiple Balloons together.  Most of the time there is just one item in that collection though (a BalloonValueSet type object).  Then you still have to set its 'override' value.

Below is an example of one possible different variation of your code that might possibly work, but no guarantees.

It is working with the 'active' sheet, then the first Balloon on that sheet (by index number, not by name), then accessing its first BalloonValueSet, then setting its override value.

' iLogic rule to change the balloon value by asking the user to enter a value

Dim valueEntered As String

' Prompt the user to enter a value
valueEntered = InputBox("Enter the value for the balloon:", "Balloon Value")

' Check if the user entered a value
If valueEntered <> "" Then
    ' Update the balloon value with the user-entered value
	 ThisDrawing.ActiveSheet.Balloons.NativeEntity.Item(1).BalloonValueSets.Item(1).OverrideValue = valueEntered
Else
    MsgBox("No value entered. Balloon value remains unchanged.")
End If

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

naveedmX3N25
Contributor
Contributor
Thank you for correcting my code.
It is possible to make it some a way that it only overrides the balloon that I have selected?
0 Likes
Message 4 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Hi @naveedmX3N25.  Sure.  Here is another iLogic code example that will allow you to either pre-select (before you run the rule), or 'pick' one (while the rule is running), then do essentially the same thing.

' iLogic rule to change the balloon value by asking the user to enter a value
Dim oDDoc As DrawingDocument = ThisDrawing.Document
'Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
'Dim oBalloons As Inventor.Balloons = oSheet.Balloons
'If oBalloons.Count = 0 Then Return 'exit rule - no Balloons on the active sheet
Dim oSS As SelectSet = oDDoc.SelectSet
Dim oBalloon As Inventor.Balloon = Nothing
If oSS.Count > 0 Then
	If TypeOf oSS.Item(1) Is Inventor.Balloon Then
		oBalloon = oSS.Item(1)
	End If
Else
	oBalloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select A Balloon")
End If
If oBalloon Is Nothing Then
	MsgBox("No Balloon pre-selected or picked.  Exiting rule.")
	Return 'exit rule because no Balloon was selected
End If
'get its first BalloonValueSet
Dim oBVS As BalloonValueSet = oBalloon.BalloonValueSets.Item(1)
'prompt user to enter new value for the Balloon, showing its current value as default value
Dim valueEntered As String = InputBox("Enter the value for the balloon.", "Balloon Value", oBVS.ItemNumber)
' Check if the user entered a value
If valueEntered <> "" Then
    ' Update the balloon value with the user-entered value
	 oBVS.OverrideValue = valueEntered
Else
    MsgBox("No value entered. Balloon value remains unchanged.")
End If

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 5 of 10

J-Camper
Advisor
Advisor
Accepted solution

This will have the user select a balloon to change and then be prompted for the input value:

 

 

Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
If IsNothing(dDoc) Then Logger.Debug("Not Run In Drawing Document") : Exit Sub
	
Dim PickBalloon As Balloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a Balloon")

While PickBalloon IsNot Nothing
	Dim valueEntered As String = InputBox("Enter the value for the balloon:", "Balloon Value", PickBalloon.BalloonValueSets.Item(1).OverrideValue)
	If valueEntered Is String.Empty Then MsgBox("No value entered. Balloon value remains unchanged.") : Exit While
	
	PickBalloon.BalloonValueSets.Item(1).OverrideValue = valueEntered
	PickBalloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a Balloon")
End While

 

 

Is this what you want?

 

Edit: Didn't notice before replying myself

Message 6 of 10

naveedmX3N25
Contributor
Contributor
Thanks for this Code.
I am trying to figure out on how make this so that I can select multiple ones and make all of them the same override value.
Currently when I try it doesn't.
0 Likes
Message 7 of 10

J-Camper
Advisor
Advisor
Accepted solution

@naveedmX3N25,

This will let you pre-select then change all selected to the same entered value OR let you enter a value then select balloons to change one-by-one:

Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
If IsNothing(dDoc) Then Logger.Debug("Not Run In Drawing Document") : Exit Sub

Dim valueEntered As String = InputBox("Enter the value for the balloon(s):", "Balloon Value")
If valueEntered Is String.Empty Then MsgBox("No value entered") : Exit Sub

If dDoc.SelectSet.OfType(Of Balloon).Count < 1
	Dim PickBalloon As Balloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a Balloon")
	
	While PickBalloon IsNot Nothing
		PickBalloon.BalloonValueSets.Item(1).OverrideValue = valueEntered
		PickBalloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a Balloon")
	End While
Else
	Dim SelectedBallons As IEnumerable = dDoc.SelectSet.OfType(Of Balloon)
	For Each b As Balloon In SelectedBallons
		b.BalloonValueSets.Item(1).OverrideValue = valueEntered
	Next
End If	

 

 

 It will create a new undo item for each balloon changed. 

 

This version will batch all the changes into a single transaction envelope:

Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
If IsNothing(dDoc) Then Logger.Debug("Not Run In Drawing Document") : Exit Sub

Dim valueEntered As String = InputBox("Enter the value for the balloon(s):", "Balloon Value")
If valueEntered Is String.Empty Then MsgBox("No value entered.") : Exit Sub

Dim transMan As TransactionManager = ThisApplication.TransactionManager
Dim oTrans As Transaction = transMan.StartTransaction(dDoc, "Batch Balloon Overrides")
On Error GoTo Errrr
	

If dDoc.SelectSet.OfType(Of Balloon).Count < 1
	Dim PickBalloon As Balloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a Balloon")
	
	While PickBalloon IsNot Nothing
		PickBalloon.BalloonValueSets.Item(1).OverrideValue = valueEntered

		PickBalloon = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingBalloonFilter, "Select a Balloon")
	End While
Else
	Dim SelectedBallons As IEnumerable = dDoc.SelectSet.OfType(Of Balloon)
	For Each b As Balloon In SelectedBallons
		b.BalloonValueSets.Item(1).OverrideValue = valueEntered

	Next
End If	
	
oTrans.End 'Typical transaction end

Exit Sub 'Finish the Sub routine before Error Handling code

Errrr :
MsgBox("Aborted: " & transMan.CurrentTransaction.DisplayName) : transMan.CurrentTransaction.Abort 
Exit Sub

 

 

Let me know if you have any questions

 

**Edit: Made corrections to code based on my comment in message 9

0 Likes
Message 8 of 10

naveedmX3N25
Contributor
Contributor
Thank you, great knowledge!!
0 Likes
Message 9 of 10

J-Camper
Advisor
Advisor

@naveedmX3N25,

 

I realized something after posting.  I was using the .Cast(Of Object) on the selectset, but that will throw an error if more than just balloons are selected.  Please change all ".Cast" To ".OfType" [Lines 7 & 15 of first block | Lines 12 & 21 of second block]

 

I will also post the second block as a txt file, with those 2 lines corrected.

0 Likes
Message 10 of 10

naveedmX3N25
Contributor
Contributor
Thank you worked perfectly!
0 Likes