I already wrote some Macros in Catia V5 built in Macro Editor, but i can't figure out how to access Catia commands from Excel.
I would like to know how can I create for instance a simple straight cylinder by only having in the excel file cylinder's radius and length.
I want to make different pressure vessels in Catia by entering their diameter and height in Excel and after clicking on a button in that excel sheet the vessel should appear in Catia. I have no problem if I already need to have an open empty part in Catia, but would be best just to have Catia Opened with nothing loaded in it.
If i have the start and see how can I access Catia Methods from Excel I think I can figure out the rest methods needed to complete the vessel, like neck, cap, etc.
Thank you.
Edit: I managed to test some stuff, I got stuck on one problem, I don't know how to set up constraints in Excel vba. I moved the code from Catia vb to Visual Express and managed to make it work there but in excel I don't find a link on how to use a driving dimension.
Here is my code:
Sub Main()
Dim CATIA As Object
Set CATIA = GetObject(, "CATIA.Application")
Set openDocument = CATIA.ActiveDocument
Set currentPart = openDocument.Part
Set currentHybridBodies = currentPart.HybridBodies
Set currentHybridBody = currentHybridBodies.Add()
Set referenceHybridBody = currentPart.CreateReferenceFromObject(currentHybridBody)
currentPart.HybridShapeFactory.ChangeFeatureName referenceHybridBody, "GeometricalSet"
Set partOriginElements = currentPart.OriginElements
Set plnYZ = currentPart.OriginElements.PlaneYZ
Set currentGeometricalSet = currentPart.HybridShapeFactory
Dim currentOffset As Integer
Dim circleDiameter As Integer
Dim cylinderLength As Integer
currentOffset = 0
circleDiameter = Range("B2").Value
cylinderLength = Range("B3").Value
Call CreateCylinder(0, 0, circleDiameter, cylinderLength, currentOffset)
currentPart.Update
currentOffset = currentOffset + cylinderLength
circleDiameter = Range("B5").Value
cylinderLength = Range("B6").Value
Call CreateCylinder(0, 0, circleDiameter, cylinderLength, currentOffset)
openDocument.Part.Update
currentOffset = currentOffset + cylinderLength
circleDiameter = Range("B8").Value
cylinderLength = Range("B9").Value
Call CreateCylinder(0, 0, circleDiameter, cylinderLength, currentOffset)
currentPart.Update
currentOffset = currentOffset + cylinderLength
CATIA.ActiveWindow.ActiveViewer.Reframe
End Sub
Sub CreateCylinder(iCenterX, iCenterY, iDiameter, iLength, iPlaneOffset)
Set CATIA = GetObject(, "CATIA.Application")
Set openDocument = CATIA.ActiveDocument
Set currentPart = openDocument.Part
Set plnYZ = currentPart.OriginElements.PlaneYZ
Set currentGeometricalSet = currentPart.HybridShapeFactory
Set planeOffset1 = currentGeometricalSet.AddNewPlaneOffset(plnYZ, iPlaneOffset, False)
Set currentHybridBody = currentPart.HybridBodies.Item("GeometricalSet")
currentHybridBody.AppendHybridShape (planeOffset1)
openDocument.Part.Update
Set currentBodies = currentPart.Bodies
Set currentBody = currentBodies.Add()
Set currentSketch = currentBody.Sketches.Add(planeOffset1)
Dim Factory2D As Object
Set Factory2D = currentSketch.OpenEdition
Set geometricElements1 = currentSketch.GeometricElements
Dim axis2D1 As Object
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Dim line2D1 As Object
Set line2D1 = axis2D1.GetItem("HDirection")
Dim line2D2 As Object
Set line2D2 = axis2D1.GetItem("VDirection")
Set currentCircle = Factory2D.CreateClosedCircle(iCenterX, iCenterY, iDiameter / 2)
Dim point2D1 As Object
Set point2D1 = axis2D1.GetItem("Origin")
Dim constraints1 As Object
Set constraints1 = currentSketch.Constraints
Dim reference2 As Object
Set reference2 = currentPart.CreateReferenceFromObject(currentCircle)
Dim constraint1 As Object
Set constraint1 = constraints1.AddMonoEltCst(catCstTypeRadius, reference2)
Dim catCstModeDrivingDimensions As Object
'Set constraint1.Mode = catCstModeDrivingDimensions 'Here I get the error
Dim iRadius As Double
iRadius = iDiameter / 2
currentCircle.CenterPoint = point2D1
currentSketch.CloseEdition
Dim newPad As Object
Set newPad = currentPart.ShapeFactory.AddNewPad(currentSketch, iLength)
End Sub
On that commented line I get error 438: Object doesn't support this property or method.
The code works without that line, but the geometric elements are not constrained, instead they appear fixed and I don't want this.
That code works fine in Visual Express and put all the constraints where they should be.
Can anyone tell me how to link that Catia command to excel vb.
This is from v5 automation documentation:
enum CatConstraintMode { catCstModeDrivingDimension, catCstModeDrivenDimension }
Also any feedback on my code is appreciated.
Thank you.
Edit: The only references I seem to be allowed to import are these: references
If I select others I receive an error: Error in loading DLL. Catia is installed on a server but I can point to it using Browse... still I'm not sure what to select there because there are a lot of files.