ILOGIC - ThisApplication.ActiveView - push value into active view Iproperty

ILOGIC - ThisApplication.ActiveView - push value into active view Iproperty

Anonymous
Not applicable
1,158 Views
4 Replies
Message 1 of 5

ILOGIC - ThisApplication.ActiveView - push value into active view Iproperty

Anonymous
Not applicable

I like to manually set component part numbers which I use for parts list and ballooning and usually do this through the BOM.  However sometimes when first laying out a multi-sheet drawing, I'd like to simply select a drawing view and enter the part number or description on the fly. 

 

I've cobbled together some iLogic but it seems to be tripping up with ThisApplication.ActiveView.  Can someone please review my rule and tell me what I am doing wrong?  Thanks!

 

SyntaxEditor Code Snippet

'Exit if not drawing document
Sub Main()
	If Not ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
		Messagebox.Show("Current document is not drawing docuemnt", "Inventor")
		Exit Sub
	End If

'Prompt for new part number and description
	Dim oPartnumber As String
	oPartnumber = InputBox("Enter new part number", "Update part number")
	Dim oDescription As String
	oDescription = InputBox("Enter new description", "Update description")
	
'Access the currently active view	
	Dim oView As DrawingView
	oView = ThisApplication.ActiveView	
	oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName=""
	oModelName = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName

'get file type and append to referenced document name
	oViewModelType = oView.ReferencedDocumentDescriptor.ReferencedDocument
	If oViewModelType.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
		oModelName = oModelName + ".ipt"
	Else If oViewModelType.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
		oModelName = oModelName + ".iam"
	Else	
		oModelName = oModelName + ".ipn"
	End If	

'update the component properties with new values
	Try
	iProperties.Value(oModelName, "Project", "Part Number") = oPartnumber
	iProperties.Value(oModelName, "Project", "Description") = oDescription
	InventorVb.DocumentUpdate()
	Catch
	'do nothing if error
	End Try
End Sub 

0 Likes
1,159 Views
4 Replies
Replies (4)
Message 2 of 5

BrianEkins
Mentor
Mentor

In the API, a View object represents a graphics window not a drawing view. There's no such thing as an active drawing view but from the Application you can get the active document and if it's a drawing you can get the active sheet from the document. From the sheet you can access all of its drawing views.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks for your reply.

 

Is there a way to designate only the currently selected drawing view for the rule?

0 Likes
Message 4 of 5

BrianEkins
Mentor
Mentor

From the drawing document you can get the SelectSet. It's a collection of everything that's currently selected. You can check the count and if it's 1, then you can check that the item is a DrawingView and then use it.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks Brian. I'm quite the novice but will give it a shot.

0 Likes