get value of balloons and copy to iproperties of each in parts list

get value of balloons and copy to iproperties of each in parts list

Anonymous
Not applicable
1,047 Views
9 Replies
Message 1 of 10

get value of balloons and copy to iproperties of each in parts list

Anonymous
Not applicable

Hi Guys,

 

Anyone have any rules that I can run in drawing to - 

 

Get the value of balloon for every item (assembly or part) in the parts list and copy it to a iproperty in the model files. 

 

Thanks,

0 Likes
Accepted solutions (1)
1,048 Views
9 Replies
Replies (9)
Message 2 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below iLogic code to copy balloon no. to custom iProperties of model document.

 

Sub Main()
	Dim doc = ThisDoc.Document

	If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
		Dim oSheet As Sheet 
		oSheet = ActiveSheet.Sheet 
		
		Dim oBalloon As Inventor.Balloon 
		For Each oBalloon In oSheet.Balloons 
			Dim oReferDoc As Document
			oReferDoc = oBalloon.BalloonValueSets.Item(1).ReferencedFiles.Item(1).ReferencedDocument
			
			Update_Balloon_Number(oBalloon.BalloonValueSets.Item(1).ItemNumber, oReferDoc)
		Next
	Else
		MessageBox.Show("Current docuement is not Drawing", "Document")
	End If
End Sub

Sub Update_Balloon_Number(ByVal ItemNumber As String, ByVal oDoc As Document) 

	Try
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Balloon_Number").Value = ItemNumber
	Catch
		'catch error when iproperty doesn't exist and create it
		oDoc.PropertySets.Item("Inventor User Defined Properties").Add("", "Balloon_Number")
		'then set the property
		oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Balloon_Number").Value = ItemNumber
	End Try

	
End Sub 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 10

Anonymous
Not applicable

This rule runs but doesn't seem to work. After I run it when I check the parts custom iprop the "Balloon_Number" property hasn't been created.

 

Thanks,

 

Sandy

0 Likes
Message 4 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please sample drawing file with assembly to test? Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 10

Anonymous
Not applicable

No I cant send the files unfortunately due to confidentiality. 

 

The reason I am doing this is because I ultimately want to add a prefix to my item numbers in the parts list. 

 

In the BOM you can add expressions to every column (i.e. to display 2 values) except the 'Item' column. This cannot be edited.  I was trying to duplicate all the items numbers to a custom property to I can then add to this to display 2 values. 

 

Perhaps this wont work.....do you know of any way to add a prefix to balloon numbers?

 

Sandy

0 Likes
Message 6 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below iLogic code to add prefix to balloon number.

 

Sub Main()
	Dim doc = ThisDoc.Document

	If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
		Dim oSheet As Sheet 
		oSheet = ActiveSheet.Sheet 
		
		Dim oBalloon As Inventor.Balloon 
		For Each oBalloon In oSheet.Balloons 
			oBalloon.BalloonValueSets.Item(1).value = "00-" + oBalloon.BalloonValueSets.Item(1).ItemNumber 
		Next
	Else
		MessageBox.Show("Current docuement is not Drawing", "Document")
	End If
End Sub

Please feel free to contact if there is any queries.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 10

Anonymous
Not applicable

Yes this works although if an item is ballooned twice it will add the prefix twice...…..can it be changed to item or part rather then balloon?

 

Also, would like to add a '-' between prefix and balloon number.  How can I do this? I have edited the code below so it prefix the property 'Title'

 

See below.

 

Thanks,

Sandy 

 

 

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 6452 StartFragment: 314 EndFragment: 6420 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Sub Main()
    Dim doc = ThisDoc.Document

    If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
        Dim oSheet As Sheet 
        oSheet = ActiveSheet.Sheet 
        
        Dim oBalloon As Inventor.Balloon 
        For Each oBalloon In oSheet.Balloons 
            oBalloon.BalloonValueSets.Item(1).Value = iProperties.Value("Summary", "Title") + oBalloon.BalloonValueSets.Item(1).ItemNumber 
        Next
    Else
        MessageBox.Show("Current docuement is not Drawing", "Document")
    End If
End Subscreen snap.PNG

 

 

 

0 Likes
Message 8 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Anonymous,

 

Try this iLogic code now.

Sub Main()
    Dim doc = ThisDoc.Document

    If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
        Dim oSheet As Sheet 
        oSheet = ActiveSheet.Sheet 
        Dim al As New ArrayList()
        Dim oBalloon As Inventor.Balloon 
        For Each oBalloon In oSheet.Balloons 
            
			
			If Not (al.Contains(oBalloon.BalloonValueSets.Item(1).ItemNumber )) Then
			    al.Add(oBalloon.BalloonValueSets.Item(1).ItemNumber )
			End If

        Next
		Dim i As Integer = 0
		For Each oBalloon In oSheet.Balloons 
			If oBalloon.BalloonValueSets.Item(1).ItemNumber = al(i) Then
				oBalloon.BalloonValueSets.Item(1).Value = iProperties.Value("Summary", "Title") + " - "+ oBalloon.BalloonValueSets.Item(1).Value 
				i = i + 1
			End If
		Next
    Else
        MessageBox.Show("Current docuement is not Drawing", "Document")
    End If
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 10

Anonymous
Not applicable

Cheers. 

 

Would there be any code to reset item number to static value? (I.e. remove the prefix)

 

Thanks,

 

Sandy

0 Likes
Message 10 of 10

Anonymous
Not applicable

Found this:

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 5878 StartFragment: 314 EndFragment: 5846 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oPartsList As Partslist
oPartsList = oSheet.PartsLists(1)

Dim oRow As PartsListRow
Dim oColumn As PartsListColumn

For Each oRow In oPartsList.PartsListRows
For Each oColumn In oPartsList.PartsListColumns
    oRow.Item(oColumn).Static = False
    Next oColumn
Next oRow

iLogicVb.RunRule("Renumber Items")
0 Likes