iLogic: Open a document, measure extents, save them to iproperties

iLogic: Open a document, measure extents, save them to iproperties

abhijit
Explorer Explorer
1,201 Views
2 Replies
Message 1 of 3

iLogic: Open a document, measure extents, save them to iproperties

abhijit
Explorer
Explorer

So I am trying to run a loop on all components in assembly and save part extent details to its iproperties. But ilogic function "Measure" doesn't work as it's capturing details of open assembly instead of part that I've opened.  Also when I save iproperties, it's getting saved in assembly file instead of opened part doc. I think I am missing something major about how iLogic scope works.

 

Any solution?

 

Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

'work the the drawing files for the referenced models
'this expects that the model has been saved
For Each oRefDoc In oRefDocs
	iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"
	'check that model is saved
	If(System.IO.File.Exists(iptPathName)) Then
		Dim oDrawDoc As PartDocument
		oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)

		Try
			' TODO: measure dimensions of opened part
			Dim x = Measure.ExtentsLength
			Dim y = Measure.ExtentsWidth
			Dim z = Measure.ExtentsHeight

			Dim Thick = MinOfMany (x, y, z)
			Dim Length = MaxOfMany (x, y, z)
			Dim Width = x + y + z - Thick - Length

			' TODO: Write to open document
			iProperties.Value("Custom", "THICKNESS")= Thick
			iProperties.Value("Custom", "WIDTH")= Width
			iProperties.Value("Custom", "LENGTH")= Length
			iProperties.Value("Custom", "RM Type") = "Plate"
			oDrawDoc.Save

		Catch
		End Try
		oDrawDoc.Close
	Else
	End If
Next
0 Likes
Accepted solutions (1)
1,202 Views
2 Replies
Replies (2)
Message 2 of 3

abhijit
Explorer
Explorer

I've figured out editing iproperties part like this, still need to get Measure function to work on opened document:

 

' DONE: Edit properties of opened file
Dim oSubPropSet As PropertySet
oSubPropSet = oDrawDoc.PropertySets.Item("User Defined Properties")

oSubPropSet.Add(Thick, "THICKNESS")
oSubPropSet.Add(Width, "WIDTH")
oSubPropSet.Add(Length, "LENGTH")
oSubPropSet.Add("Plate", "RM Type")

oDrawDoc.Save

 

0 Likes
Message 3 of 3

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, here is a code that adds the measures to the parties I have not checked it well, but I think it should work well. Add the line to skip the assembly document, so do not place the measurements in this type of file.

 

Dim oAsmDoc As AssemblyDocument= ThisDoc.Document

For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
	If oRefDoc.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
		customPropertySet = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
		
		Dim oX As Double = 0
		Dim oY As Double = 0
		Dim oZ As Double = 0
		For Each oBody As SurfaceBody In oRefDoc.ComponentDefinition.SurfaceBodies
			oBodyX = Round(oBody.RangeBox.MaxPoint.X - oBody.RangeBox.MinPoint.X, 2)
			oBodyY = Round(oBody.RangeBox.MaxPoint.Y - oBody.RangeBox.MinPoint.Y, 2)
			oBodyZ = Round(oBody.RangeBox.MaxPoint.Z - oBody.RangeBox.MinPoint.Z, 2)
			
			If oBodyX > oX Then oX = oBodyX 
			If oBodyY > oY Then oY = oBodyY 
			If oBodyZ > oZ Then oZ = oBodyZ 	
		Next
		
		Dim Thick = MinOfMany (oX, oY, oZ)
		Dim Length = MaxOfMany (oX, oY, oZ)
		Dim Width = oX + oY + oZ - Thick - Length

		' Write to open document
		Try
		  customPropertySet.Item("THICKNESS").Value = Thick * 10 & " mm"	
		Catch
		  customPropertySet.Add("", "THICKNESS")
		  customPropertySet.Item("THICKNESS").Value = Thick * 10 & " mm"
		End Try
		Try
		  customPropertySet.Item("WIDTH").Value = Width * 10 & " mm"	
		Catch
		  customPropertySet.Add("", "WIDTH")
		  customPropertySet.Item("WIDTH").Value = Width * 10 & " mm"
		End Try
		Try
		  customPropertySet.Item("LENGTH").Value = Length * 10 & " mm"	
		Catch
		  customPropertySet.Add("", "LENGTH")
		  customPropertySet.Item("LENGTH").Value = Length * 10 & " mm"	
		End Try
		
		oRefDoc.Save
		
	End If
Next

 I hope it is useful. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn