Automatic exploded view

Automatic exploded view

GeorgK
Advisor Advisor
5,623 Views
13 Replies
Message 1 of 14

Automatic exploded view

GeorgK
Advisor
Advisor

Hello together,

 

is it possible to create an exploded view of an assmbly like in the good old days with VB.Net or iLogic?

 

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/simplecontent/content/in...

 

Thank you

 

Georg

 

 

0 Likes
5,624 Views
13 Replies
Replies (13)
Message 2 of 14

chandra.shekar.g
Autodesk Support
Autodesk Support

Hello @GeorgK,

 

In Inventor API 2018, many objects, properties and events of presentation documents are added. Which are listed in the following link.
http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-36B1FFB5-5291-4532-8F11-90E912769B34


Currently, Inventor API still not allowed to add new scene (i.e, placing a assembly document an creating exploded view in presentation document).

 

Inventor API 2014 was supporting for querying exploded view only. Since Inventor 2017, there is a big change in the API related to presentation document. So, the old APIs for Inventor 2014 won't work.

 

Please log this wish list at ide station using below link.

https://forums.autodesk.com/t5/inventor-ideas/idb-p/v1232/tab/most-recent

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 14

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

do you have some sample code for Inventor 2018?

 

Thank you

 

Georg

0 Likes
Message 4 of 14

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

 

 

Currently, there is no sample code for presentation document of Inventor 2018. Please let me know the task that you are trying, I will try to create code for it.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 14

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

the idea was to get the same result as in the old versions of Inventor. Start the program and each part moves away from it's position. Each part should be seen after the move. There should be a variable to set the distance for the parts.

 

Thank you

 

Georg

0 Likes
Message 6 of 14

AlexFielder
Advisor
Advisor

@GeorgK, I know the function you speak of, it being sorely missed in Inventor since it was removed with the update to the presentation environment.

 

I suppose the "explode" function present in the (online) model viewer would provide the same functionality; perhaps @chandra.shekar.g can find for us the code that does it and share it here? Then (and it would likely be no small task) it could in theory be re-engineered to work with Inventor once again?

0 Likes
Message 7 of 14

AlexFielder
Advisor
Advisor

Thinking about it further, I propose that you could calculate a collection of centre of mass point3D objects and move them apart by a set amount from the geometric centre of the assembly you are working within.

 

That sounds a lot easier than it probably is, as I suspect you would maybe need to calculate the geometric centre of each part/assembly instead and then perform a tweak on a vector away from the geometric centre of the parent assembly document.

 

You could I suppose also allow for an "explosion whilst respecting physical constraints" such that the assembly would dismantle in the way that it is physically able but again that's a lot of work.

Message 8 of 14

chandra.shekar.g
Autodesk Support
Autodesk Support

@AlexFielder,

 

I checked with Engineering team and confirmed that Inventor 2014 API was supporting exploded view for presentation document. Since Inventor 2017 does not exploded view for presentation document.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 14

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

is there any workaround to get the same result with Inventor 2017 / 2018 and VB.Net?

 

Georg

0 Likes
Message 10 of 14

AlexFielder
Advisor
Advisor

Hi @GeorgK,

 

Here's the beginnings of a rule I worked up last week for this.

 

So far all it does is create workpoints at the boundingbox centre for each top-level occurrence. The next logical step would (I think) be to "explode" these points apart by a set distance.

 

Then of course it would need to be made to work in the Presentation environment and translate those exploded positions into Tweaks.

 

Which is some ways away I think.

 

Anyways, here's my code so far:

 

Sub Main()
	Dim points As New List(Of KeyValuePair(Of String, Point))
	Dim thisAssy As AssemblyDocument = ThisApplication.ActiveDocument
	Dim originMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
	Dim destinationMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
	Dim originPoint As WorkPoint = thisAssy.ComponentDefinition.WorkPoints.Item(1)
	originPoint.Visible = True
	Dim occurrenceYNormal As UnitVector = Nothing

	For Each occ As ComponentOccurrence In thisAssy.ComponentDefinition.Occurrences
		Dim oTransform As Matrix = occ.Transformation
		Dim occDatum As WorkPoint = Nothing
		If TypeOf (occ.Definition.Document) Is PartDocument Then
			Dim IsAPart As PartDocument = occ.Definition.Document
			Dim partXYWorkPlane As WorkPlane = IsAPart.ComponentDefinition.WorkPlanes(1)
			Dim normalPlane As Plane = partXYWorkPlane.Plane
			occurrenceYNormal = ThisApplication.TransientGeometry.CreateUnitVector(normalPlane.Normal.X, normalPlane.Normal.Y, normalPlane.Normal.Z)
			occDatum = IsAPart.ComponentDefinition.WorkPoints(1)
			occDatum.Visible = False
		Else
			Dim IsAnAssembly As AssemblyDocument = occ.Definition.Document
			Dim assyXYWorkPlane As WorkPlane = IsAnAssembly.ComponentDefinition.WorkPlanes(1)
			Dim normalPlane As Plane = assyXYWorkPlane.Plane
			occurrenceYNormal = ThisApplication.TransientGeometry.CreateUnitVector(normalPlane.Normal.X, normalPlane.Normal.Y, normalPlane.Normal.Z)
			occDatum = IsAnAssembly.ComponentDefinition.WorkPoints(1)
			occDatum.Visible = False
		End If
		Dim compdef As ComponentDefinition = occ.Definition
		originMatrix.SetTranslation(originPoint.Point.VectorTo(occDatum.Point))
		Dim originYVector As Vector  = ThisApplication.TransientGeometry.CreateVector(0, 1, 0)
		originMatrix.SetToRotateTo(originYVector, occurrenceYNormal.AsVector())
		Dim tmpPoint As Point = getBoxCentreFromOccurrence(occ)
		points.Add(New KeyValuePair(Of String, Point)(occ.Name, tmpPoint))
	Next

	For Each pnt As KeyValuePair(Of String, Point) In points
		Dim point As Point = pnt.Value
		Dim wp As WorkPoint = thisAssy.ComponentDefinition.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint(point.X, point.Y, point.Z))
		wp.Name = "Work Point: " & pnt.Key
	Next

End Sub

Function getBoxCentreFromComponentDefinition (thiscompDef As ComponentDefinition) As Point
	Dim centrepoint As Point = ThisApplication.TransientGeometry.CreatePoint((thiscompDef.RangeBox.MaxPoint.X - thiscompDef.RangeBox.MinPoint.X) / 2, 
	(thiscompDef.RangeBox.MaxPoint.Y - thiscompDef.RangeBox.MinPoint.Y) / 2,
	(thiscompDef.RangeBox.MaxPoint.Z - thiscompDef.RangeBox.MinPoint.Z) / 2)
	Return centrepoint
End Function

Function getBoxCentreFromOccurrence(thisocc As ComponentOccurrence) As Point
	Dim centrepoint As Point = ThisApplication.TransientGeometry.CreatePoint((thisocc.RangeBox.MaxPoint.X - thisocc.RangeBox.MinPoint.X) / 2 + thisocc.RangeBox.MinPoint.X, 
	(thisocc.RangeBox.MaxPoint.Y - thisocc.RangeBox.MinPoint.Y) / 2 + thisocc.RangeBox.MinPoint.Y,
	(thisocc.RangeBox.MaxPoint.Z - thisocc.RangeBox.MinPoint.Z) / 2 + thisocc.RangeBox.MinPoint.Z)
	Return centrepoint
End Function

Incidentally, this forms part of my iLogic github repo here: https://github.com/AlexFielder/iLogic

 

Maybe I'm overthinking it (It has been known to happen) so please, anyone who has a better idea do speak up. 

 

🙂

 

PS. @chandra.shekar.g I perhaps wasn't clear in my suggestion to speak to your team; I meant to ask them if the "explode" javascript function available in the Autodesk web viewer could be repurposed into iLogic to save us the trouble? I had a look around myself to see if I could find what it was based upon but to no avail, although I have one other avenue left to explore.

Message 11 of 14

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Suggestion by @AlexFielder would be a workaround to explode occurrence in assembly.

 


@AlexFielder wrote:

 

 

PS. @chandra.shekar.g I perhaps wasn't clear in my suggestion to speak to your team; I meant to ask them if the "explode" javascript function available in the Autodesk web viewer could be repurposed into iLogic to save us the trouble? I had a look around myself to see if I could find what it was based upon but to no avail, although I have one other avenue left to explore.


"explode" javascript function is from Forge API (web service API).

 

Thanks and regards,

 

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 12 of 14

mjkoushik
Explorer
Explorer

Pretty interesting approach. Has anyone worked on this to complete the automation of exploded view.??. Does inventor 2021 have the capability to automate exploded view using Presentation API

0 Likes
Message 13 of 14

Maxim-CADman77
Advisor
Advisor
I know this is an old thread but I wonder if somebody moved any further with this?

Please vote for Inventor-Idea Text Search within Option Names

Message 14 of 14

james_brandtKXBGN
Explorer
Explorer

Here is an iLogic rule you can try and play with. It was build from @AlexFielder . Thank you!

Sub Main()

    Dim doc As Inventor.Document = ThisDoc.Document
    If doc Is Nothing Then Return
    If doc.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then Return

    Dim asm As Inventor.AssemblyDocument = DirectCast(doc, Inventor.AssemblyDocument)
    Dim app As Inventor.Application = ThisApplication
    Dim tg As Inventor.TransientGeometry = app.TransientGeometry
    Dim cd As Inventor.AssemblyComponentDefinition = asm.ComponentDefinition

    '---------------------------
    ' Model State: Exploded
    '---------------------------
    Dim ms As Inventor.ModelStates = cd.ModelStates
    Dim targetName As String = "Exploded"

    Dim exists As Boolean = False
    For Each s As Inventor.ModelState In ms
        If String.Equals(s.Name, targetName, StringComparison.OrdinalIgnoreCase) Then
            exists = True
            Exit For
        End If
    Next

    If Not exists Then
        ms.Add(targetName)
    End If

    ms.Item(targetName).Activate()

    '---------------------------
    ' Explode parameters
    '---------------------------
    Dim uom As UnitsOfMeasure = asm.UnitsOfMeasure

    ' Base explode distance
    Dim explodeDist As Double = uom.ConvertUnits(50.0, "in", uom.LengthUnits) ' 10 inches in doc length units (internal)

    ' Optional: small extra “spread” to reduce stacking (tangential nudge)
    Dim tangentialDist As Double = uom.ConvertUnits(2.0, "in", uom.LengthUnits) ' 2 inches

    '---------------------------
    ' Assembly center (RangeBox)
    '---------------------------
    Dim asmCenter As Point = BoxCenter(cd.RangeBox, tg)

    '---------------------------
    ' Apply explode transform
    '---------------------------
    For Each occ As ComponentOccurrence In cd.Occurrences

        If occ Is Nothing Then Continue For
        If occ.Suppressed Then Continue For
        If occ.Grounded Then Continue For ' grounded occurrences won't move anyway; skip

        ' Occurrence center in assembly space
        Dim occCenter As Point = BoxCenter(occ.RangeBox, tg)

        ' Direction away from assembly center
        Dim dir As Vector = asmCenter.VectorTo(occCenter)
        If dir.Length < 0.000001 Then
            dir = tg.CreateVector(0, 1, 0) ' fallback
        Else
            dir.Normalize()
        End If

        ' Primary radial move
        Dim moveVec As Vector = dir.Copy()
        moveVec.ScaleBy(explodeDist)

        ' Tangential nudge (helps when multiple parts share same radial direction)
        Dim up As Vector = tg.CreateVector(0, 0, 1) ' global Z
        Dim tan As Vector = up.CrossProduct(dir)
        If tan.Length > 0.000001 Then
            tan.Normalize()
            tan.ScaleBy(tangentialDist)
            moveVec.AddVector(tan)
        End If

        ' Keep existing rotation, add translation
        Dim m As Matrix = occ.Transformation

        Dim newT As Vector = m.Translation.Copy()
        newT.AddVector(moveVec)

        ' False = do not reset orientation (keep rotation)
        m.SetTranslation(newT, False)

        ' Move without constraint solving
        occ.SetTransformWithoutConstraints(m)

    Next

    asm.Update()

End Sub


Function BoxCenter(b As Box, tg As TransientGeometry) As Point
    Return tg.CreatePoint( _
        (b.MinPoint.X + b.MaxPoint.X) * 0.5, _
        (b.MinPoint.Y + b.MaxPoint.Y) * 0.5, _
        (b.MinPoint.Z + b.MaxPoint.Z) * 0.5 _
    )
End Function