Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Find baloon and zoom contains number Inputbox

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
dusan.naus.trz
511 Views, 8 Replies

iLogic Find baloon and zoom contains number Inputbox

Hello,  Is something like this possible through iLogic? Does anyone have an idea how to do this?

Running iLogic in a drawing.

myparam = InputBox("Write the number of the position/baloon you are looking for", "Find baloon and zoom contains number Inputbox", "Default Entry")

MessageBox.Show("All sheets contain only =x= occurrences of the searched number of the given balloon." & vbLf & "The active sheet contains =x= searched balloons.", "Title")


'It always starts searching on the active sheet and then continues to other views or other sheets. It switches to the given sheet and zooms in on the balloon number you are looking for.
'If it contains only one baloon of the searched number, then the Msg box will not be displayed. The msg box with the option to continue is displayed only if there are more than one.
MessageBox.Show("Do you want to continue to the next balloon occurrence?", "Title",MessageBoxButtons.YesNo)

2023-02-09_21h09_20.png

8 REPLIES 8
Message 2 of 9

try something like this:

Sub Main()

    Dim itemNr As String = InputBox(
			"Write the number of the position/baloon you are looking for", 
			"Find baloon and zoom contains number Inputbox", "")

    Dim doc As DrawingDocument = ThisDoc.Document

    Dim activeSheet As Sheet = doc.ActiveSheet

    If (SearchBaolloon(activeSheet, itemNr)) Then Exit Sub

    For Each sheet As Sheet In doc.Sheets
        If (Sheet Is activeSheet) Then Continue For
        If (SearchBaolloon(activeSheet, itemNr)) Then Exit Sub
    Next

End Sub

Public Function SearchBaolloon(sheet As Sheet, itemNr As String)
    For Each balloon As Balloon In sheet.Balloons
        If (Balloon.BalloonValueSets.Item(1).ItemNumber = itemNr) Then

            Dim p = Balloon.Position
            Dim target = ThisApplication.TransientGeometry.CreatePoint(p.X, p.Y, 0)
            Dim eye = ThisApplication.TransientGeometry.CreatePoint(p.X, p.Y, 100)

            Dim diameter = Balloon.Style.BalloonDiameter
            ' looking at a full size baloon is no fun. Therefore we zoom out a bit
            diameter = diameter * 7.5

            Dim camera As Camera = ThisApplication.ActiveView.Camera
            camera.Target = target
            camera.Eye = eye
            camera.SetExtents(diameter, diameter)
            camera.Apply()

            Dim result = MessageBox.Show(
				"Do you want to continue to the next balloon occurrence?", 
				"Title", MessageBoxButtons.YesNo)
            If (result = DialogResult.No) Then
                Return True
            End If
        End If
    Next
    Return False
End Function

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 9

@JelteDeJong 

Thank you very much. This is incredible. It's amazing. I didn't think such a thing was possible.

Message 4 of 9

@JelteDeJong 

According to the picture. I tried to find Baloon/Item 3 and nothing happened. Is there a trick to it?

2023-02-11_17h18_37.png

 

Message 5 of 9

I did not think of testing the attached balloons. But with a small adjustment, I can solve that. Have a look at his code:

Sub Main()

    Dim itemNr As String = InputBox(
            "Write the number of the position/baloon you are looking for",
            "Find baloon and zoom contains number Inputbox", "")

    Dim doc As DrawingDocument = ThisDoc.Document

    Dim activeSheet As Sheet = doc.ActiveSheet

    If (SearchBaolloon(activeSheet, itemNr)) Then Exit Sub

    For Each sheet As Sheet In doc.Sheets
        If (Sheet Is activeSheet) Then Continue For
        If (SearchBaolloon(activeSheet, itemNr)) Then Exit Sub
    Next

End Sub

Public Function SearchBaolloon(sheet As Sheet, itemNr As String)
    For Each balloon As Balloon In sheet.Balloons
        For Each valueSet As BalloonValueSet In Balloon.BalloonValueSets
            If (valueSet.ItemNumber = itemNr) Then

                ZoomToBalloon(Balloon)

                Dim result = MessageBox.Show(
                    "Do you want to continue to the next balloon occurrence?",
                    "Title", MessageBoxButtons.YesNo)
                If (result = DialogResult.No) Then
                    Return True
                End If
            End If
        Next
    Next
    Return False
End Function

Public Sub ZoomToBalloon(balloon As Balloon)
    Dim p = balloon.Position
    Dim target = ThisApplication.TransientGeometry.CreatePoint(p.X, p.Y, 0)
    Dim eye = ThisApplication.TransientGeometry.CreatePoint(p.X, p.Y, 100)

    Dim diameter = balloon.Style.BalloonDiameter
    ' looking at a full size baloon is no fun. Therefore we zoom out a bit
    diameter = diameter * 7.5

    Dim camera As Camera = ThisApplication.ActiveView.Camera
    camera.Target = target
    camera.Eye = eye
    camera.SetExtents(diameter, diameter)
    camera.Apply()
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 9

@JelteDeJong 

Thank you very much for your patience. It's perfect.

Message 7 of 9
Jesper_S
in reply to: JelteDeJong

Hi.

 

Really nice piece of iLogic, will come to good use.

 

I got a code to locate on what view and sheet a balloon is located.

Only thing is that it won't locate balloons that are in a group.

 

You perhaps got a fix for that?

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the active sheet.
Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet


Dim oBalloon As Balloon
Dim oBalloonValueSet As BalloonValueSet

Dim oSheet As Sheet
For Each oSheet In oDrawDoc.Sheets
	If oMesssage = "" Then
		oMesssage = oSheet.Name
	Else
		oMesssage = oMesssage & vbLf & oSheet.Name
	End If
	oSheet.Activate
	For Each oBalloon In oDrawDoc.ActiveSheet.Balloons
		oViewName = oBalloon.ParentView.Name
		oItem = oBalloon.BalloonValueSets.Item(1).Value
		oMesssage = oMesssage & vbLf & "Balloon # " & oItem & " is on " & oViewName
	Next
	oMesssage = oMesssage & vbLf & "___________________"
Next

oActiveSheet.Activate 'return to original sheet
MessageBox.Show(oMesssage, "iLogic")

//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Message 8 of 9
dusan.naus.trz
in reply to: Jesper_S

@Jesper_S 

I modified the code a bit.
Do you mean something like that?

Class ThisRule
	Dim moje As Integer = 1

	Sub main

		'	MessageBox.Show("zacatek" & moje, "Title")
		'		Dim itemNr As String = InputBox(
		'		"Write the number of the position/baloon you are looking for",
		'		"Find baloon and zoom contains number Inputbox", "")

		Dim itemNr As String = InputBox(
		"CZ = Napište číslo pozice, které hledáte" & vbLf & "EN = Write the position number you are looking for", "Umístění Pozice na všech listech/Show location Baloon in All Sheets")

		If itemNr = "" Then
			MessageBox.Show("CZ = Příkaz ukončen" & vbLf & "EN = The command ended.", "Ukončení příkazu")

			Return 'exit rule
		End If

		Dim oDrawDoc As DrawingDocument
		oDrawDoc = ThisApplication.ActiveDocument

		' Set a reference to the active sheet.
		Dim oActiveSheet As Sheet
		oActiveSheet = oDrawDoc.ActiveSheet

		Dim oBalloon As Balloon
		Dim oBalloonValueSet As BalloonValueSet

		Dim oSheet As Sheet
		For Each oSheet In oDrawDoc.Sheets
			oSheet.Activate
			'		MessageBox.Show("pp" & moje, "Title")
			If moje = 2 Then
				Exit For
				Exit Sub
			Else
				'			MessageBox.Show("funkce" & moje, "Title")
				SearchBaolloon(oSheet, itemNr)
			End If
			If moje = 2 Then Exit For
		Next
		If moje = 2 Then Exit Sub
		oActiveSheet.Activate 'return to original sheet

	End Sub

	Public Sub SearchBaolloon(sheet As Sheet, itemNr As String)

		'	For Each balloon As Balloon In Sheet.Balloons
		'		If (Balloon.BalloonValueSets.Item(1).ItemNumber = itemNr) Then
		For Each balloon As Balloon In sheet.Balloons
			For Each valueSet As BalloonValueSet In Balloon.BalloonValueSets
				If (valueSet.ItemNumber = itemNr) Then


					Dim p = Balloon.Position
					Dim target = ThisApplication.TransientGeometry.CreatePoint(p.X, p.Y, 0)
					Dim eye = ThisApplication.TransientGeometry.CreatePoint(p.X, p.Y, 100)

					Dim diameter = Balloon.Style.BalloonDiameter
					' looking at a full size baloon is no fun. Therefore we zoom out a bit
					diameter = diameter * 7.5

					Dim camera As Camera = ThisApplication.ActiveView.Camera
					camera.Target = target
					camera.Eye = eye
					camera.SetExtents(diameter, diameter)
					camera.Apply()

					Dim result = MessageBox.Show(
					"CZ = Chcete pokračovat k dalšímu výskytu pozice?" & vbLf & "EN = Do you want to continue to the next balloon occurrence?",
					"Pokračuj na další pozici/Continue next Baloon", MessageBoxButtons.YesNo)

					If (result = DialogResult.No) Then
						moje = 2
						MessageBox.Show("CZ = Příkaz ukončen" & vbLf & "EN = The command ended.", "Ukončení příkazu")
'						MessageBox.Show("Ne" & moje, "Title")

						Exit For
						Exit Sub
					Else
						moje = 1
					End If
				End If

						If moje = 2 Then Exit For
			Next
			If moje = 2 Then Exit For
			'	If moje = 2 Then Exit Sub'Function
			'    Return Nothing'Return False
		Next
	End Sub

End Class
Message 9 of 9
Jesper_S
in reply to: dusan.naus.trz

Hi.

 

No.

Want the ballons that are connected to the first ballonon the view to show up in the list as well.

Jesper_S_0-1676369175219.png

Now, it only shows the first ballon, in the case above, item 19, 22 & 22 (Again) in View B, but the other ballons don't show up.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report