Run the SketchProjectCutEdgesCmd from top level assembly

Run the SketchProjectCutEdgesCmd from top level assembly

Anonymous
Not applicable
1,059 Views
5 Replies
Message 1 of 6

Run the SketchProjectCutEdgesCmd from top level assembly

Anonymous
Not applicable

Hello everybody,

 

I need some help with the following issue.

 

I wrote a rule wich generally works fine. 

 

-The rule checks in wich direction the part is in the workspace, and create a new sketch.

-rename the sketch to identify

-create a iProperty for the edgelenght of the projected edges, measure the value, and set to the iProperty

-close and delete the sketch.

 

If i fire the rule in the part...everything works

If i fire the rule as a external rule in the part...everything works

 

But

 

if i fire the rule from the assembly (run rule in component comand) then the edges will not be projected and the rule stops working.

the same if i fire the rule as an external rule from top level assembly

 

 

I need this for cuting time calculation of the hole assembly, so later i add all the loops measured an have a time for the cuttind duration of all the parts. 😉 

 

 

Any help would be great!

 

I m sure the error occures in the control definition of the project comand, but i dont know how and why!

 

 

I add a simple assembly for demonstrating the problem as zip.

 

 

Thanks

 

Simon

 

 

SyntaxEditor Code Snippet

'Set all to Zero

iProperties.Value("Custom", "X")=Round(Measure.ExtentsLength)
iProperties.Value("Custom", "Y")=Round(Measure.ExtentsWidth)
iProperties.Value("Custom", "Z")=Round(Measure.ExtentsHeight)

iProperties.Value("Custom", "Loop")=0
iProperties.Value("Custom", "Loop_SETM")=0
iProperties.Value("Custom", "Loop_SELM")=0
    
Dim opartDoc As Inventor.PartDocument 
opartDoc = ThisDoc.Document
' Set a reference to the part component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
' Create a new sketch on plane`

'Get the orientation Of the Part_______________________XYZ

If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "Z") Then
n=3
Else If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "Y") Then
n=2
Else If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "X") Then
n=1
End If

Dim oSketch1 As PlanarSketch
oSketch1 = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(n))
'edit the Sketch
oSketch1.Edit

' Set a reference To the transient geometry Object.

Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry

'project cut edges
Dim oDef As ControlDefinition
oDef = ThisApplication.CommandManager.ControlDefinitions.Item("SketchProjectCutEdgesCmd")
oDef.Execute
'close Sketch
oSketch1.ExitEdit
'Rename the Sketch To identify
oSketch1.Name = "Temp_Loop"
'Write the Loop To the iproperty
iProperties.Value("Custom", "Loop")=Measure.Perimeter("Temp_Loop")
RuleParametersOutput()
'delete the Sketch
oSketch1.Delete
opartDoc.Update()
InventorVb.DocumentUpdate()

 

 

 

 

0 Likes
Accepted solutions (1)
1,060 Views
5 Replies
Replies (5)
Message 2 of 6

MechMachineMan
Advisor
Advisor

From what I can remember during a brief stint with using Project cut edges, I think you need to open the part for edit if you are projecting the cut edges into a part, and also select the occurrences with edges to project before running the command.

 

Good luck.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 6

Anonymous
Not applicable

Hello MechMachine,

 

Thanks for reply, but the SketchProjectCutEdgesCmd works.

The rule crates the curves, measure the value and save it to the iProperty.

 

My problem is that i cant run the rule as external (or run rule in component comand) from an Assembly

 

Any Idea?

0 Likes
Message 4 of 6

MechMachineMan
Advisor
Advisor

Hmm Yes. Makes sense.

 

It would be failing at the bolded line because what ThisDoc.Document returns in the italicized line would be an Inventor.AssemblyDocument type.

 

You need to put in more error proofing in the code and expand upon the logic of how its supposed to work.

 

'Set all to Zero

iProperties.Value("Custom", "X")=Round(Measure.ExtentsLength)
iProperties.Value("Custom", "Y")=Round(Measure.ExtentsWidth)
iProperties.Value("Custom", "Z")=Round(Measure.ExtentsHeight)

iProperties.Value("Custom", "Loop")=0
iProperties.Value("Custom", "Loop_SETM")=0
iProperties.Value("Custom", "Loop_SELM")=0
    
Dim opartDoc As Inventor.PartDocument 
opartDoc = ThisDoc.Document
' Set a reference to the part component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
' Create a new sketch on plane`

'Get the orientation Of the Part_______________________XYZ

If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "Z") Then
n=3
Else If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "Y") Then
n=2
Else If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "X") Then
n=1
End If

Dim oSketch1 As PlanarSketch
oSketch1 = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(n))
'edit the Sketch
oSketch1.Edit

' Set a reference To the transient geometry Object.

Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry

'project cut edges
Dim oDef As ControlDefinition
oDef = ThisApplication.CommandManager.ControlDefinitions.Item("SketchProjectCutEdgesCmd")
oDef.Execute
'close Sketch
oSketch1.ExitEdit
'Rename the Sketch To identify
oSketch1.Name = "Temp_Loop"
'Write the Loop To the iproperty
iProperties.Value("Custom", "Loop")=Measure.Perimeter("Temp_Loop")
RuleParametersOutput()
'delete the Sketch
oSketch1.Delete
opartDoc.Update()
InventorVb.DocumentUpdate()

 

I would try my luck with it modified as below.

 

'Set all to Zero

iProperties.Value("Custom", "X")=Round(Measure.ExtentsLength)
iProperties.Value("Custom", "Y")=Round(Measure.ExtentsWidth)
iProperties.Value("Custom", "Z")=Round(Measure.ExtentsHeight)

iProperties.Value("Custom", "Loop")=0
iProperties.Value("Custom", "Loop_SETM")=0
iProperties.Value("Custom", "Loop_SELM")=0
    
Dim oDoc As Inventor.Document 
oDoc = ThisApplication.ActiveDocument
' Set a reference to the component definition.
Dim oCompDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition
' Create a new sketch on plane`

'Get the orientation Of the Part_______________________XYZ

If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "Z") Then
n=3
Else If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "Y") Then
n=2
Else If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "X") Then
n=1
End If

Dim oSketch1 As PlanarSketch
oSketch1 = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(n))
'edit the Sketch
oSketch1.Edit

' Set a reference To the transient geometry Object.

Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry

'project cut edges
Dim oDef As ControlDefinition
oDef = ThisApplication.CommandManager.ControlDefinitions.Item("SketchProjectCutEdgesCmd")
oDef.Execute
'close Sketch
oSketch1.ExitEdit
'Rename the Sketch To identify
oSketch1.Name = "Temp_Loop"
'Write the Loop To the iproperty
iProperties.Value("Custom", "Loop")=Measure.Perimeter("Temp_Loop")
RuleParametersOutput()
'delete the Sketch
oSketch1.Delete
oDoc.Update()
InventorVb.DocumentUpdate()

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 6

Anonymous
Not applicable

^^^^Thanks Mech machine, but does not work

 

Ok,

 

After dealing with the API modell i  found the solution by my own.

 

I Think the problem was that i used the transient geometry wich is in "this Application"

 

 

Now i use the  "SurfaceBodies" of the "Part component definion" for my Geometry.

I also dont use the control definition, i use the ProjectedCuts comand of the planar sketches definition

 

 

What ever, it works! May someone can explain me why?

 

 

I can fire the rule....in the part,

..............................as external rule in the part

..............................from assembly in the part,

..............................from assembly as external rule in the part

 

So everything is fine!

 

Thanks!

 

 

 
 

 

 

 

 

SyntaxEditor Code Snippet

'Set all to Zero

iProperties.Value("Custom", "X")=Round(Measure.ExtentsLength)
iProperties.Value("Custom", "Y")=Round(Measure.ExtentsWidth)
iProperties.Value("Custom", "Z")=Round(Measure.ExtentsHeight)

iProperties.Value("Custom", "Loop")=0
iProperties.Value("Custom", "Loop_SETM")=0
iProperties.Value("Custom", "Loop_SELM")=0
    
Dim oPartDoc As PartDocument
oPartDoc =  ThisDoc.Document

' Set a reference to the part component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
' Create a new sketch on plane`

'Get the orientation Of the Part_______________________XYZ

If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "Z") Then
n=3
Else If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "Y") Then
n=2
Else If MinOfMany(iProperties.Value("Custom", "X"),iProperties.Value("Custom", "Y"),iProperties.Value("Custom", "Z"))=iProperties.Value("Custom", "X") Then
n=1
End If

Dim oSketch1 As PlanarSketch
oSketch1 = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(n))
'edit the Sketch
oSketch1.Edit

' Set a reference To BODY of the PART wich i m workin with.

 Dim SBody As SurfaceBodies
 SBody = oCompDef.SurfaceBodies
 
'Project the cuts Not the cut edges

oSketch1.ProjectedCuts.Add()

'Exit
oSketch1.ExitEdit

'Rename the Sketch To identify

oSketch1.Name = "Temp_Loop"

'Write the Loop To the iproperty

iProperties.Value("Custom", "Loop")=Measure.Perimeter("Temp_Loop")
RuleParametersOutput()

'delete the Sketch
oSketch1.Delete
oPartDoc.Update

 

 

 

 

0 Likes
Message 6 of 6

Anonymous
Not applicable
Accepted solution

The error is where MM Stated:

 

Dim oPartDoc As PartDocument
oPartDoc =  ThisDoc.Document

 When a rule is run from an assembly the  (ThisDoc) is an assembly document. Not a part document.

 

You need to traverse the assembly to get to the sub components/occurrences.

 

SyntaxEditor Code Snippet

'____Iteration Template for Assembly Structures_______
Sub Main()

    Dim oAsmDoc As AssemblyDocument 

    oAsmDoc = ThisApplication.ActiveDocument  

    Call Iterate(oAsmDoc.ComponentDefinition.Occurrences, 1)

End Sub 


Private Sub Iterate(Occurrences As ComponentOccurrences, Level As Integer) 
''Iterate through Assembly Occurrences

    Dim oOcc As ComponentOccurrence
    Dim sName As String

    For Each oOcc In Occurrences 
    ''Find Parts in Assembly
        sName = oOcc.Name

        Try 
        'Investigate Occurence and 'Do Something'
            Select Case oOcc.DefinitionDocumentType 
                Case kAssemblyDocumentObject
                    ''Do something to an Assembly

                Case kPartDocumentObject
                    ''Do something to a Part

                Case kForeignModelDocumentObject

                Case kSATFileDocumentObject

                Case kNoDocument

                Case Else
                    ''Do something if an object is misidentified

            End Select

        Catch ex As Exception
        'MsgBox("There was an Error! --" & ex.Message)            


        Finally
        ''Run through the sub assemblies 
            If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
                Call Iterate(oOcc.SubOccurrences, Level + 1) 
            End If 

        End Try

    Next 
End Sub