Zobrazit plnou verzi příspěvku: Měření smyčky v náčrtu

kosulic
18.02.2014, 09:33
Zkouším udělat pravidlo na měření smyčky z náčrtu (model řetězu)Potřebuji vytvořit 4 parametry (nejlépe je označit pro export)Změřit smyčkuvypočítat počet článkůvypočítat počet spojekNefunguje mi ale zaokrouhlování a nevím jak parametry označit pro export.Kdyby se našla dobrá duše, která by mi pomohla, byl bych vděčný.Try Param = ThisDoc.Document.ComponentDefinition.Parameters("DELKA_SMYCKY")
Catch
Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression("DELKA_SMYCKY", 1, "mm" )
End Try

Dim se As SketchEntity = ThisDoc.Document.ComponentDefinition.Sketches(1).SketchLines(1)
Param.Expression =(ThisApplication.MeasureTools.GetLoopLength(se)*10 & " mm")
Parameter("DELKA_SMYCKY") = Round(DELKA_SMYCKY)

Try
Param = ThisDoc.Document.ComponentDefinition.Parameters("ROZTEC_RETEZU")
Catch
Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression("ROZTEC_RETEZU", 1, "mm" )
End Try
Parameter("ROZTEC_RETEZU") = 12.7

Try
Param = ThisDoc.Document.ComponentDefinition.Parameters("POCET_CLANKU")
Catch
Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression("POCET_CLANKU", 1, "ul" )
End Try
Parameter("POCET_CLANKU") = Round(DELKA_SMYCKY/ROZTEC_RETEZU)

Try
Param = ThisDoc.Document.ComponentDefinition.Parameters("SPOJKA_POCET")
Catch
Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression("SPOJKA_POCET", 1, "ul" )
End Try
Parameter("SPOJKA_POCET") = Floor((DELKA_SMYCKY/5000))+1

Navara
18.02.2014, 20:00


V tom kódu je několik formálních chyb a měl by vypadat takhle:[code]Dim Param As ParameterTry    Param = ThisDoc.Document.ComponentDefinition.Parameters("DELKA_SMYCKY")Catch    Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression("DELKA_SMYCKY", 1, "mm")End TryDim se As SketchEntity = ThisDoc.Document.ComponentDefinition.Sketches(1).SketchLines(1)Dim delkaRetezu As Double = Math.Round(ThisApplication.MeasureTools.GetLoopLength(se)) * 10Param.Expression = (delkaRetezu & " mm")Try    Param = ThisDoc.Document.ComponentDefinition.Parameters("ROZTEC_RETEZU")Catch    Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression("ROZTEC_RETEZU", 1, "mm")End TryDim roztecRetezu As Double = 12.7Param.Expression = roztecRetezu & "mm"Try    Param = ThisDoc.Document.ComponentDefinition.Parameters("POCET_CLANKU")Catch    Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression("POCET_CLANKU", 1, "ul")End TryDim pocetClanku As Integer = Math.Round(delkaRetezu / roztecRetezu)Param.Expression = pocetClanku & "ul"Try    Param = ThisDoc.Document.ComponentDefinition.Parameters("SPOJKA_POCET")Catch    Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression("SPOJKA_POCET", 1, "ul")End TryParam.Expression = Math.Floor((delkaRetezu / 5000)) + 1 & "ul"[/code] ale asi bych dal přednost zkrácené verzi s voláním funkce pro nastavení parametru a jeho p5enosem do iVlastnosti [code]Sub Main()    Dim se As SketchEntity = ThisDoc.Document.ComponentDefinition.Sketches(1).SketchLines(1)    Dim delkaRetezu As Double = Math.Round(ThisApplication.MeasureTools.GetLoopLength(se)) * 10    SetParam("DELKA_SMYCKY", delkaRetezu, " mm")    Dim roztecRetezu As Double = 12.7    SetParam("ROZTEC_RETEZU", roztecRetezu, "mm")    Dim pocetClanku As Integer = Math.Round(delkaRetezu / roztecRetezu)    SetParam("POCET_CLANKU", pocetClanku, "ul")    SetParam("SPOJKA_POCET", Math.Floor((delkaRetezu / 5000)) + 1, "ul")End SubSub SetParam(paramName As String, value As Double, units As String)    Dim Param As Parameter    Try        Param = ThisDoc.Document.ComponentDefinition.Parameters(paramName)    Catch        Param = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByExpression(paramName, 1, units)    End Try    Param.Expression = String.Format("{0} {1}", value, units)    'Set as property    Param.ExposedAsProperty = True    Param.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kOneDecimalPlacePrecision    Param.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType    Param.CustomPropertyFormat.ShowTrailingZeros = False    Param.CustomPropertyFormat.ShowUnitsString = False    '...End Sub[/code] 

kosulic
20.02.2014, 10:49
Děkuji, mrknu na to a vyzkouším.