Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Insert part and product inside product 1

Status
Not open for further replies.

Sidtha

Aerospace
Nov 25, 2012
30
Dear All,

I want insert an STD part inside a product using vba please help me for it.

---First need to create a new product using insert new product name should be (STD_parts)
---After this need call STD parts from the local folder and positioned in a product.
Parts should be place using excel co ordinates like below.
PartNumber Fasteners Diameter Type Xe Ye Ze Xdir Ydir Zdir
D5724085500000 Fasteners Diameter_0.313_(5/16")_|_7.9mm en6114K5-12.263 4821.16mm 3237.365mm 194.177mm -0.033227856 0.058947539 -0.997707922
D5724085500000 Fasteners Diameter_0.313_(5/16")_|_7.9mm en6114K5-12.264 4858.672mm 3251.013mm 193.735mm -0.033599881 0.05992018 -0.997637519


insert_pk7slr.jpg


i have recorded below macro but unable to edit that.


Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim products1 As Products
Set products1 = product1.Products

Dim product2 As Product
Set product2 = products1.Item("D0005039219800.1")

Dim products2 As Products
Set products2 = product2.Products

Dim product3 As Product
Set product3 = products2.Item("D5724085500000.1")

Dim products3 As Products
Set products3 = product3.Products

Dim product4 As Product
Set product4 = products3.AddNewProduct("STD_parts")
 
Replies continue below

Recommended for you

Hi ferdo,

Yes i am able to insert a STD parts from CADLIB, but i am facing issue as its not placing properly with HnF reference. below is my result.
STD_lvs8zz.jpg


Could you please help me to place properly.
Below is the code to place the STD parts
Sub CATMain()

lastRow = WS.Cells(Rows.Count, 1).End(xlUp).Row

Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim products1 As Products
Set products1 = product1.Products

Dim product2 As Product
Set product2 = products1.Item(1)

'---Loop through every tree node for the current product (fasterner)
k = 3
For i = 1 To products1.Count
Set oCurrentTreeNode = products1.Item(i)
MyCurrFastner = oCurrentTreeNode.PartNumber
X = Left(MyCurrFastner, 2)
Y = UCase(Left(Cells(k, 40).Value, 2))
If X = Y Then
Bolt = UCase(Cells(k, 40).Value)
'Dim Xdir As Integer, Ydir As Integer, Zdir As Integer
Xdir = WS.Cells(k, 8).Value
Ydir = WS.Cells(k, 9).Value
Zdir = WS.Cells(k, 10).Value
'Dim Xe As Integer, Ye As Integer, Ze As Integer
Xe = WS.Cells(k, 5).Value
Ye = WS.Cells(k, 6).Value
Ze = WS.Cells(k, 7).Value

Dim move1
Set move1 = oCurrentTreeNode.Move

Set move1 = move1.MovableObject
Dim arrayOfVariantOfDouble1(11)
arrayOfVariantOfDouble1(0) = 1
arrayOfVariantOfDouble1(1) = 0
arrayOfVariantOfDouble1(2) = Xdir '-xdir
arrayOfVariantOfDouble1(3) = 0
arrayOfVariantOfDouble1(4) = 1
arrayOfVariantOfDouble1(5) = Ydir '+ydir
arrayOfVariantOfDouble1(6) = -(Xdir) '+xdir
arrayOfVariantOfDouble1(7) = -(Ydir) '-ydir
arrayOfVariantOfDouble1(8) = -(Zdir) '+zdir
arrayOfVariantOfDouble1(9) = Xe
arrayOfVariantOfDouble1(10) = Ye
arrayOfVariantOfDouble1(11) = Ze
Set move1Variant = move1
move1Variant.Apply arrayOfVariantOfDouble1
k = k + 1
End If

Next i

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor