How to use iLogic IManagedDrawing.AddManagedEntity Method

How to use iLogic IManagedDrawing.AddManagedEntity Method

Josh_Hunt
Advocate Advocate
786 Views
6 Replies
Message 1 of 7

How to use iLogic IManagedDrawing.AddManagedEntity Method

Josh_Hunt
Advocate
Advocate

Reference Help: ALL 3 AddManagedEntity METHODS

I am most interested in AddManagedEntity Method (String, Func(Object, Boolean), Func(Object))

 

AddManagedEntity is not anywhere in the forums so I'm curious if anyone has used this or Autodesk can clarify.

This feature sounds very powerful if it works the way I think it does.

----------------------------

I think I understand the fundamentals of how to make Func(Object, Boolean)  but maybe I'm missing something.

 

I want to use AddManagedEntity to 'Manage' a Drawing BreakOutOperation.

 

However, BreakOutOperations.Add(profile, depthSource, depthValue, SectionAllParts) requires 2-4 arguments.

 

Do I pass in the 2-4 arguments into the "Object" of the Function?

Is the Object the BreakOutOperation or do I need to make a new class ManagedBreakOutOperation ?

Josh Hunt
787 Views
6 Replies
Replies (6)
Message 2 of 7

JelteDeJong
Mentor
Mentor

you can use the IManagedDrawing.AddManagedEntity like this:

ThisDrawing.AddManagedEntity(
	"entityName",
	Function(obj)
' obj is the object you need to check MsgBox("Edit the entity, or check to see if it requires editing. ") ' return True if the entity has been edited satisfactorily, ' and can be kept. If the entity needs to be modified but ' the API doesn't allow the required edits, then this should return False. Return True End Function, Function() ' The old entitie is deleted automaticaly if this function is called MsgBox("This function is called if the other function returned false.") ' create the new entity and rturn it. Return theNewObject 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

0 Likes
Message 3 of 7

Josh_Hunt
Advocate
Advocate

@JelteDeJong Thank you,

I understand 2nd arguments need to be..

Func(Of Object, Boolean)

 and 3rd argument needs to be...

Func(Of Object)

but creating a BreakOutOperation requires in 5 objects (DrawingView, Profile, GeometryIntent, depthValue As Double, SectionAllParts As Boolean )

 

How do I pass that information into those 2 arguments?

 

If more details would help then below is what I'm doing now. It sort of works but my end goal is to create 1 simplified function that uses AddManagedEntity(String, Func(Object, Boolean), Func(Object)) https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=55931a54-5145-dad9-5f6e-3e15ef6bdd4e

 

 

	Public Function CreateBreakOut(imdv As IManagedDrawingView,
									ThisDrawing As IManagedDrawing,
									name As String,
									partName As String,
									intentName As String,
									radius As Double,
									Optional depthValue As Double = 0,
									Optional SectionAllParts As Boolean = True) As BreakOutOperation

		Dim sketchName = name & "_Sketch"

		'Delete and recreate each time is much simpler than trying to update each time
		ThisDrawing.DeleteManagedEntity(name)
		ThisDrawing.DeleteManagedEntity(sketchName)

		Dim dv As DrawingView = imdv.NativeEntity

		'IMAGNIT FRAMEWORK METHOD
		Dim giSheet As GeometryIntent = imdv.GetIntent(partName, intentName)
		Dim dvcS As DrawingViewCurves = DrawingViewCurves.GetEdgeGroup(dv.DrawingCurves, dv)
		Dim intents As GeometryIntentCollection = dvcS.Intents
		giSheet = intents.OrderByClosestTo(giSheet.PointOnSheet).FirstOrDefault    'redefine to the closest drawing curve intent

		'CREATE
		Dim sketch As DrawingSketch = dv.Sketches.Add()
		sketch.Name = sketchName
		'Sketch
		Dim skCenterPoint As Point2d = sketch.SheetToSketchSpace(giSheet.PointOnSheet)

		Dim circumfrencePt2d As Point2d = skCenterPoint.Copy
		circumfrencePt2d.X += radius '? UNITS

		sketch.Edit()   '!IMPORTANT
		Dim lines = sketch.SketchLines.AddAsPolygon(7, skCenterPoint, circumfrencePt2d, True)
		sketch.ExitEdit()   '!IMPORTANT

		'Profile and Operation
		Dim prof As Profile = sketch.Profiles.AddForSolid()
		Dim this As BreakOutOperation = dv.BreakOutOperations.Add(prof, giSheet, depthValue, SectionAllParts)

		'Manage so this gets auto deleted if it is not created
		ThisDrawing.AddManagedEntity(name, this)
		ThisDrawing.AddManagedEntity(sketchName, sketch)

		Return this
	End Function

 

 

Josh Hunt
0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Hi @Josh_Hunt .

I have not tried to use that iLogic method before either, and likely for the same reason...Autodesk is notoriously bad about not providing nearly enough information or examples about their iLogic only objects and methods.  However, one thing that immediately comes to mind as an input object in your case would be an Array of Object.  The array is one object, but can contain all necessary elements of data that would need to be worked with within each of the two delegate functions.  Just a thought that seemed worthy of testing.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

Josh_Hunt
Advocate
Advocate

@WCrihfield Thank you, that does give me an idea to pass a Structure, dictionary(Of String, Object), or a Tuple

Josh Hunt
0 Likes
Message 6 of 7

JelteDeJong
Mentor
Mentor

you can try it like this:

Public Function CreateManagedBreakOut(
		imdv As IManagedDrawingView,
        ThisDrawing As IManagedDrawing,
        name As String,
        partName As String,
        intentName As String,
        radius As Double,
        Optional depthValue As Double = 0,
        Optional SectionAllParts As Boolean = True) As BreakOutOperation

    ThisDrawing.AddManagedEntity(
	name,
        Function()
            Return CreateBreakOut(
                imdv, ThisDrawing, name,
                partName, intentName, radius,
                depthValue, SectionAllParts)
        End Function)
End Function

Public Function CreateBreakOut(imdv As IManagedDrawingView,
                                ThisDrawing As IManagedDrawing,
                                name As String,
                                partName As String,
                                intentName As String,
                                radius As Double,
                                Optional depthValue As Double = 0,
                                Optional SectionAllParts As Boolean = True) As BreakOutOperation

    Dim sketchName = name & "_Sketch"

    'Delete and recreate each time is much simpler than trying to update each time
    ThisDrawing.DeleteManagedEntity(name)
    ThisDrawing.DeleteManagedEntity(sketchName)

    Dim dv As DrawingView = imdv.NativeEntity

    'IMAGNIT FRAMEWORK METHOD
    Dim giSheet As GeometryIntent = imdv.GetIntent(partName, intentName)
    Dim dvcS As DrawingViewCurves = DrawingViewCurves.GetEdgeGroup(dv.DrawingCurves, dv)
    Dim intents As GeometryIntentCollection = dvcS.Intents
    giSheet = intents.OrderByClosestTo(giSheet.PointOnSheet).FirstOrDefault    'redefine to the closest drawing curve intent

    'CREATE
    Dim sketch As DrawingSketch = dv.Sketches.Add()
    sketch.Name = sketchName
    'Sketch
    Dim skCenterPoint As Point2d = sketch.SheetToSketchSpace(giSheet.PointOnSheet)

    Dim circumfrencePt2d As Point2d = skCenterPoint.Copy
    circumfrencePt2d.X += radius '? UNITS

    sketch.Edit()   '!IMPORTANT
    Dim lines = sketch.SketchLines.AddAsPolygon(7, skCenterPoint, circumfrencePt2d, True)
    sketch.ExitEdit()   '!IMPORTANT

    'Profile and Operation
    Dim prof As Profile = sketch.Profiles.AddForSolid()
    Dim this As BreakOutOperation = dv.BreakOutOperations.Add(prof, giSheet, depthValue, SectionAllParts)

    Return this
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

0 Likes
Message 7 of 7

Josh_Hunt
Advocate
Advocate
Thank you @JelteDeJong I have already finished my project so I hope your code above works for the next person searching for this.
Josh Hunt
0 Likes