Create parameter for projected loop

Create parameter for projected loop

Anonymous
Not applicable
707 Views
4 Replies
Message 1 of 5

Create parameter for projected loop

Anonymous
Not applicable

Hi all,

 

I work within furniture manufacturing and end up using a non-modeled parts list which we all have to manually fill out. My aim is to transition it to a fully modeled parts list, so it's automatically filled out by modeled details.

One of the parts in the list is a worktop nosing. To create this we make a sketch perpendicular to the edge of the worktop and then use the sweep feature to loop it round the outer edge of the worktop. The problem here is that we approximate the total length by adding up the length and width of the worktop (adding a few hundred mm for a buffer) and manually enter it.

 

If I open up the loop sketch that the sweep feature creates, I can measure the loop line (although we still need to add a buffer). I want to add that measurement as a parameter and use it to define the Bill of Materials property.

 

Is this possible?

0 Likes
708 Views
4 Replies
Replies (4)
Message 2 of 5

tyas.swinnen
Advocate
Advocate

I found an iLogic code to calculate that for you on the forum (forgot to include the original poster's name to the code. So sorry to the OP of that code...😊)

 

'Set a reference to the active part document
    Dim oDoc As PartDocument
    oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As PartComponentDefinition
    oDef = oDoc.ComponentDefinition


    ' Set a reference to the selected feature. Make sure you name the Sweep "Sweep1" or change this variable to match the Sweep you wish to calculate
    Dim oSweep As SweepFeature
    oSweep = oDef.Features.SweepFeatures.Item("Sweep1")
    
    ' Get the centroid of the sweep profile in sketch space
    Dim oProfileOrigin As Point2d
    oProfileOrigin = oSweep.Profile.RegionProperties.Centroid
    
    ' Transform the centroid from sketch space to model space
    Dim oProfileOrigin3D As Point
    oProfileOrigin3D = oSweep.Profile.Parent.SketchToModelSpace(oProfileOrigin)
    
    ' Get the set of curves that represent the true path of the sweep
    Dim oCurves As ObjectsEnumerator
    oCurves = oDef.Features.SweepFeatures.GetTruePath(oSweep.Path, oProfileOrigin3D)
    
    Dim TotalLength As Double
    TotalLength = 0
    
    Dim oCurve As Object
    For Each oCurve In oCurves
        
        Dim oCurveEval As CurveEvaluator
        oCurveEval = oCurve.Evaluator
        
        Dim MinParam As Double
        Dim MaxParam As Double
        Dim length As Double
        
        Call oCurveEval.GetParamExtents(MinParam, MaxParam)
        Call oCurveEval.GetLengthAtParam(MinParam, MaxParam, length)
        
        TotalLength = TotalLength + length
    Next

    Dim oparams As Parameters
    Dim oparam As Parameter
    oparams = oDoc.ComponentDefinition.Parameters
    Dim exists As Boolean
    exists = False

    'Find out if parameter exists, if not it will create this parameter in the table, if you want another name then change Sweeplength to something else
    For Each oparam In oparams
    If oparam.Name = "Sweeplength" Then exists = True
    Next oparam

    'Change the value if the parameter exists otherwise add the parameter
    If exists Then
        oparams.Item("Sweeplength").Value = TotalLength
    Else
        oparams.UserParameters.AddByValue ("Sweeplength", TotalLength, 11266)
    End If
	oDoc.Update
Message 3 of 5

Anonymous
Not applicable

Thank you for your reply tyas.swinnen.

 

I am having some trouble with that code. I have modified it to replace all "Sweep1" with "A-NOSING", as in my model thats what the sweep is called:

'Set a reference to the active part document
    Dim oDoc As PartDocument
    oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As PartComponentDefinition
    oDef = oDoc.ComponentDefinition


    ' Set a reference to the selected feature. Make sure you name the Sweep "A-NOSING" or change this variable to match the Sweep you wish to calculate
    Dim oSweep As SweepFeature
    oSweep = oDef.Features.SweepFeatures.Item("A-NOSING")
    
    ' Get the centroid of the sweep profile in sketch space
    Dim oProfileOrigin As Point2d
    oProfileOrigin = oSweep.Profile.RegionProperties.Centroid
    
    ' Transform the centroid from sketch space to model space
    Dim oProfileOrigin3D As Point
    oProfileOrigin3D = oSweep.Profile.Parent.SketchToModelSpace(oProfileOrigin)
    
    ' Get the set of curves that represent the true path of the sweep
    Dim oCurves As ObjectsEnumerator
    oCurves = oDef.Features.SweepFeatures.GetTruePath(oSweep.Path, oProfileOrigin3D)
    
    Dim TotalLength As Double
    TotalLength = 0
    
    Dim oCurve As Object
    For Each oCurve In oCurves
        
        Dim oCurveEval As CurveEvaluator
        oCurveEval = oCurve.Evaluator
        
        Dim MinParam As Double
        Dim MaxParam As Double
        Dim length As Double
        
        Call oCurveEval.GetParamExtents(MinParam, MaxParam)
        Call oCurveEval.GetLengthAtParam(MinParam, MaxParam, length)
        
        TotalLength = TotalLength + length
    Next

    Dim oparams As Parameters
    Dim oparam As Parameter
    oparams = oDoc.ComponentDefinition.Parameters
    Dim exists As Boolean
    exists = False

    'Find out if parameter exists, if not it will create this parameter in the table, if you want another name then change Sweeplength to something else
    For Each oparam In oparams
    If oparam.Name = "Sweeplength" Then exists = True
    Next oparam

    'Change the value if the parameter exists otherwise add the parameter
    If exists Then
        oparams.Item("Sweeplength").Value = TotalLength
    Else
        oparams.UserParameters.AddByValue ("Sweeplength", TotalLength, 11266)
    End If
    oDoc.Update

 

I get the following error message:

"Error in rule: NOSING_CALC, in document: D21-9884-12-01.ipt

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"

 

With more info:

"System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.SweepFeatures.GetTruePath(Object PathCurves, Point TrueStartPoint)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"

 

I am a beginner in the world of code so it doesn't make much sense to me.

Message 4 of 5

cadman777
Advisor
Advisor

If I was you, I would move this request into the Inventor Customization forum (and reference this thread).

You're more likely to get more and quicker responses.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 5 of 5

Anonymous
Not applicable

Hi Chris, thank you. I have moved the post by creating a new post in the board you suggested, and referenced the URL of this post.

0 Likes