Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA VBA Work in Part object from Product 1

Status
Not open for further replies.

Hector Licon

Automotive
Dec 5, 2018
2
MX
Good day

I have a problem wiht a macro for create route for tubing.

The program work fine if run when have a Part document open, but I need run the program from product because need reference from other assembly elements and when I have the product open the progran dont run even if have a the part as work object and the part desing worbench

How can i work in part from product?
 
Your application probably just expects a Part document as an input, so it is just not running under a product. But without seeing a code, it is hard to give you an answer.

Tesak
- Text along a curve for Catia V5
 
Hi, yeah there is difference between those two, i don't know can you change the code or? If someone else wrote that code i guess there is condition on the beginning.
You can run it from product, but we can't help you without that code.

 
Yes, is a condition on the begining when fail the program in a product document, even when the part is selected

The first part of the code is:


Global partDocument1 As partdocument
Global Puntos_Lineas_Radios As Factory
Global part1 As part
Global axisSystems1 As AxisSystems
Global bodies1 As bodies
Global geoset As HybridBodies
Global axisSystem As axisSystem
Global Tuberia As Body
Global esqueleto_tuberia As HybridBody

--------------------------------------------------------------------------------------------
Sub CATMain()

'Define y crea body y geometrical set--------------------------------------------------------

Set partDocument1 = CATIA.ActiveDocument

Set Puntos_Lineas_Radios = CATIA.ActiveDocument.part.HybridShapeFactory

Set part1 = partDocument1.part

Set axisSystems1 = part1.AxisSystems

Set bodies1 = part1.bodies

Set geoset = part1.HybridBodies

nombre_de_linea = InputBox("Nombre de la linea")

If nombre_de_linea = "" Then Exit Sub

Set axisSystem = axisSystems1.Add()

Set Tuberia = bodies1.Add()

Set esqueleto_tuberia = geoset.Add()

Tuberia.Name = nombre_de_linea

esqueleto_tuberia.Name = nombre_de_linea

axisSystem.Name = nombre_de_linea
 
As I have mentioned already, your script expects a part document as an input. It will not work from a product without appropriate changes in your code. If you launch it from a product, you have to find your part in the product tree and get its Part object. Or another solution would be to preselect your part in the tree and get its Part object from the selection.

To get a Part object from selection you can use this code:

Code:
Sub GetPartFromSel()
    Dim doc As Document
    Set doc = CATIA.ActiveDocument
    
    Dim sel
    Set sel = doc.Selection
    
    Dim partDoc
    Set partDoc = sel.Item(1).Value.ReferenceProduct.Parent
    
    Dim myPart
    Set myPart = partDoc.Part
End Sub

Tesak
- Text along a curve for Catia V5
 
hello,all

If I understand you correctly, you want to get the Part as the red box labeled in the follow picture ?

p1_tkkvmv.png


The Following code can help to get Part object from Product :
Code1:CATIA.ActiveDocument.Product.Products.Item(1).ReferenceProduct.Parent.Part
Code2:CATIA.ActiveDocument.Selection.Search ("CATPrtSearch.PartFeature,all")

The following picture may help you understand the code as write above:

Capture_uuaq6f.png


I hope it can help you out, thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top