ilogic or vb code - derived component

ilogic or vb code - derived component

marcin_bargiel
Advocate Advocate
943 Views
7 Replies
Message 1 of 8

ilogic or vb code - derived component

marcin_bargiel
Advocate
Advocate

Hi

I need iLogic or VB code for :

1. add  derived component Part2.ipt to Part1.ipt, I actually need only Sketch3

2. then i need to Extrude, type CUT, behavior TO NEXT,  profile, from Sketch3 (circle) to Solid1 in Part1.ipt (i want to just make a hole in Part1.ipt.)

 

I attached two simple files. In Part1.ipt, there are derived Part2.ipt and Extrusion2 already done manually.

I want to obtain the same result with iLogic.

 

For clarification why i'm doing this: in fact Part2.ipt always contains complicated shapes (that i want to create only once !), then add Part1.ipt and a lot of instance Part2.ipt to ASSEMBLY.iam.
Part1.ipt it is usually a cylinder or end cap,  shape is easy but there are a lot of holes (i don't want to to this manually by planes, sketech, parameters - this is a long way)

Until now, I have used the master skeleton method, but it is not satisfactory when I have to do, for example, 100 elements in a project.
 
Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Accepted solutions (2)
944 Views
7 Replies
Replies (7)
Message 2 of 8

HideoYamada
Advisor
Advisor
Accepted solution

Hello Marcin,

 

This code create the features like as that you have created in Part1.

 

Option Explicit

Sub DerivedTest()
    Dim oDestDoc As PartDocument
    Set oDestDoc = ThisApplication.ActiveDocument
    Dim oDestDef As PartComponentDefinition
    Set oDestDef = oDestDoc.ComponentDefinition
    Dim sourceFullFileName As String
    ' This is dirty hack
    sourceFullFileName = oDestDoc.FullFileName
    Mid(sourceFullFileName, Len(sourceFullFileName) - 4, 1) = "2"
    
    ' Add Derived Part Feature
    Dim oDerivedPartComps As DerivedPartComponents
    Set oDerivedPartComps = oDestDef.ReferenceComponents.DerivedPartComponents
    
    Dim oDerivedDef As DerivedPartUniformScaleDef
    Set oDerivedDef = oDerivedPartComps.CreateUniformScaleDef(sourceFullFileName)
    oDerivedDef.ExcludeAll
    oDerivedDef.Sketches.Item("Sketch3").IncludeEntity = True
    
    Dim oDerivedPartComp As DerivedPartComponent
    Set oDerivedPartComp = oDerivedPartComps.Add(oDerivedDef)
    
    ' Add Extrude Feature
    Dim oSourceSketch As PlanarSketch
    Set oSourceSketch = oDerivedPartComp.Sketches(1)

    Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oDestDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oSourceSketch.Profiles.AddForSolid, kCutOperation)
    oExtrudeDef.SetToNextExtent kNegativeExtentDirection, oDestDef.SurfaceBodies(1)

    oDestDef.Features.ExtrudeFeatures.Add oExtrudeDef
End Sub

If you heavily use the master skeleton method, my AddIn may help your work.

UCS Derived Component 

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 3 of 8

marcin_bargiel
Advocate
Advocate

Thank's a lot !

A few things i changed :

deleted all "SET" (because of compile error)

I needed to use parenthesis here :

oExtrudeDef.SetToNextExtent(kNegativeExtentDirection, oDestDef.SurfaceBodies(1))

 

this is better for me  :

'oSourceSketch = oDerivedPartComp.Sketches(1)
 oSourceSketch = oDestDoc.ComponentDefinition.Sketches.Item("Sketch3")

 

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 4 of 8

marcin_bargiel
Advocate
Advocate

I can't figure it out how to extrude cut, when i have multibody in Part1.ipt,

1. how to extrude cut only on specific one?

2. how to extrude cut on all of them?

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 5 of 8

HideoYamada
Advisor
Advisor
Accepted solution

Hello,

 


@marcin_bargiel wrote:

1. how to extrude cut only on specific one?

Set AffectedBodies before adding an ExtrudeDefinition to a ExtrudeFeatures.

This is VBA code and you may have to modify this if you use in iLogic.

 

    Dim oCol As ObjectCollection
    Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
    ' Set the 2nd body to be cut.
  oCol.Add oDestDef.SurfaceBodies(2) oExtrudeDef.AffectedBodies = oCol oDestDef.Features.ExtrudeFeatures.Add oExtrudeDef

 

 

2. how to extrude cut on all of them?


    Dim oCol As ObjectCollection
    Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
'Add all of bodies to be cut. Dim oBody As SurfaceBody For Each oBody In oDestDef.SurfaceBodies oCol.Add oBody Next oBody oExtrudeDef.AffectedBodies = oCol oDestDef.Features.ExtrudeFeatures.Add oExtrudeDef

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 6 of 8

marcin_bargiel
Advocate
Advocate

Works as expected.

Many thanks !

 

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 7 of 8

RoyWickrama_RWEI
Advisor
Advisor

Thanks Hideo Yamada.

Reference Doc: SKIP-DOC0034

Current Doc: "SKIP-DOC0035

 

Model parameters: Dim_04, Dim_05, ..

User Parameters: Length, Width, Height, ...

 

I need the rule to be included with the reference doc and the model and user parameters so that just by running, the current document will have all those parameters. Because they are to come on many follow up documents.

I attach the sample files.

 

I request help. Thanks a lot.

 

 

2019-11-18 21_46_59-Window.png

 

 

 

0 Likes
Message 8 of 8

HideoYamada
Advisor
Advisor

Hi rwickrama,

 

I created a sample code and posted it on your thread.

 

=====

Freeradical

 Hideo Yamada

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes