cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Automatism to draw a cylinder with vb api

Gennaro
4-Participant

Automatism to draw a cylinder with vb api

Hi everyone,

Is it possible to model a cylinder via VB API ?

Thanks

3 REPLIES 3
syalagudri
12-Amethyst
(To:Gennaro)

API to create new feature is only available in Protoolkit and not in VBA.

But you can create code using UDF. In this case you need to define the UDF placements.

Gennaro
4-Participant
(To:syalagudri)

I don't have much experience with creo, could you tell me how to proceed?

Thanks

Gennaro
4-Participant
(To:Gennaro)

Hello,
in the examples provided with the creo installation, I found this function, which should create some spheres:

 

Public Function createNodeUDFInPart(ByVal placementModel As IpfcSolid, _
ByVal csysName As String, _
ByVal diameter As Double) _
As IpfcFeatureGroup

Dim csys As IpfcCoordSystem = Nothing
Dim cSystems As IpfcModelItems
Dim i As Integer
Dim udfInstructions As IpfcUDFCustomCreateInstructions
Dim csysSelection As IpfcSelection
Dim csysReference As IpfcUDFReference
Dim references As CpfcUDFReferences
Dim variantDims As IpfcUDFVariantDimension
Dim variantVals As IpfcUDFVariantValues
Dim group As IpfcFeatureGroup

Try

cSystems = placementModel.ListItems(EpfcModelItemType.EpfcITEM_COORD_SYS)

For i = 0 To cSystems.Count - 1
If (cSystems.Item(i).GetName.ToString = csysName) Then
csys = cSystems.Item(i)
Exit For
End If
Next

If csys Is Nothing Then
Throw New Exception("Coordinate System not found in current Solid")
End If

'======================================================================
'Instructions for UDF creation
'======================================================================
udfInstructions = (New CCpfcUDFCustomCreateInstructions).Create("node")

'======================================================================
'Make non variant dimensions blank to disable their display
'======================================================================
udfInstructions.DimDisplayType = EpfcUDFDimensionDisplayType.EpfcUDFDISPLAY_BLANK

'======================================================================
'Initialize the UDF reference and assign it to the instructions.
'The string argument is the reference prompt for the particular
'reference.
'======================================================================
csysSelection = (New CMpfcSelect).CreateModelItemSelection(csys, Nothing)

csysSelection.Highlight(EpfcStdColor.EpfcCOLOR_SELECTED)

csysReference = (New CCpfcUDFReference).Create("REF_CSYS", csysSelection)

references = New CpfcUDFReferences
references.Set(0, csysReference)

udfInstructions.References = references

'======================================================================
'Initialize the variant dimension and assign it to the instructions.
'The string argument is the dimension symbol for the variant dimension.
'======================================================================
variantDims = (New CCpfcUDFVariantDimension).Create("d11", diameter)
variantVals = New CpfcUDFVariantValues
variantVals.Set(0, variantDims)

udfInstructions.VariantValues = variantVals

'======================================================================
'We need the placement model for the UDF for the call to
'CreateUDFGroup(). If you were placing the UDF in a model other than
'the owner of the coordinate system, the placement would need to be
'provided separately.
'======================================================================

group = placementModel.CreateUDFGroup(udfInstructions)

Return group

Catch ex As Exception
MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)
Return Nothing
End Try

End Function

The problem is that when I invoke it, the instruction
placementModel.CreateUDFGroup (udfInstructions)
creates an exception and I can't understand why.
Can anyone help me?

Top Tags