[VBA] Create a feature using the thickness parameter as extent value

[VBA] Create a feature using the thickness parameter as extent value

Anonymous
Not applicable
693 Views
2 Replies
Message 1 of 3

[VBA] Create a feature using the thickness parameter as extent value

Anonymous
Not applicable

Hi,

I am trying to use VBA to create a cut feature with the extent value equal to the thickness of the sheet (function works for sheetmetal parts only). This is the (cropped to required) code I use:

Dim oSMDef as sheetmetalcomponentdefinition
Dim oProf as Profile
Dim oCutDef as CutDefinition
Dim oCutFeat as CutFeature
'some non-important code here that defines oProf and oSMDef etc

Set oCutDef = oSMDef.Features.CutFeatures.CreateCutDefinition(oProf)
'Call oCutDef.SetToNextExtent(kNegativeExtentDirection)
'this works, but it just uses the thickness as it is now, if it changes, it doesnt update.
Call oCutDef.SetCutAcrossBendsExtent(oSMDef.Parameters.ModelParameters.Item("Thickness").Expression)
 Set oCutFeat = oSMDef.Features.CutFeatures.Add(oCutDef)

For now, I have tried 3 things:

1. do nothing, just create the cutdefinition without setting the extent value nor direction. this works fine as the feature automatically uses the thickness as reference. However, it uses the thickness as blind value. if the sheet thickness is increased afterwards, the cut feature will not adjust (thus becoming a blind cut). 

2. SetToNextExtent, this worked fine. but, it occured (this makes 1. also invalid) that it is required to use CutAcrossBends incase it cuts over a bending.

3. SetCutAcrossBendsExtent, this is the function that must be used. as parameter I tried at first the simple method: "oSMDef.Thickness.Value". This yielded the same issue as with 1. Looking into Cutfeatures created manually, I noticed the extent distance is directly coupled to the modelparameter (the thickness). but if I try to link this using the method seen in the code above, it still uses the thickness as a blind value it is at this moment.

 

Is it possible to set the cut extent value to the thickness model property? and if so, how?

 

Thanks in advance,

 

Peter Verheijen

0 Likes
Accepted solutions (1)
694 Views
2 Replies
Replies (2)
Message 2 of 3

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

hi, We need to define part of the code in a more complete way in your example.
Here I send you an attachment with a VBA code that may be useful. I enclose an ilogic rule that performs the same action.

 

Sub Add_CutFeature()

    Dim doc As PartDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim oSMDef As SheetMetalComponentDefinition
    Set oSMDef = doc.ComponentDefinition
    Dim Ske As PlanarSketch
    Set Ske = oSMDef.Sketches(2)
    
    Dim oProf As Profile
    Set oProf = Ske.Profiles.AddForSolid(True)
    
    
    Dim oThick As String
    oThick = oSMDef.Thickness.Name
    
    
    Dim oCutDef As CutDefinition
    Set oCutDef = oSMDef.Features.CutFeatures.CreateCutDefinition(oProf)
    
    Call oCutDef.SetCutAcrossBendsExtent(oThick)
    
    Dim oCutFeat As CutFeature
    Set oCutFeat = oSMDef.Features.CutFeatures.Add(oCutDef)

End Sub

I hope this helps with your problem. 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

Message 3 of 3

Anonymous
Not applicable

Using oSMDef.Thickness.name did the trick indeed. if I edit the created cut feature manually, it even shows the "thickness" as extent value. Thanks!

0 Likes