Continue to Site

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!

Array of Parts according to selection

Status
Not open for further replies.

lukaszsz

Aerospace
Oct 16, 2012
71
PL
Code:
Sub CATMain()
Dim ArrayOfParts() 'As Object
Dim ArrayOfParts_size 'As Integer
Dim SelectedPart 'As Object
Dim PartFilt(0)
Set ProdDoc1 = CATIA.ActiveDocument
Set SelectedParts = ProdDoc1.Selection
PartFilt(0) = "Part"
Dim ret
ArrayOfParts_size = -1
SelectedParts.Clear
ret = SelectedParts.SelectElement2(PartFilt, "Select Part", False)
ArrayOfParts_size = ArrayOfParts_size + 1
ReDim Preserve ArrayOfParts(ArrayOfParts_size)
MsgBox TypeName(SelectedParts.Item(1).Value)
MsgBox ArrayOfParts_size
ArrayOfParts(ArrayOfParts_size) = SelectedParts.Item(1).Value
End Sub


Hello everyone
I've got problem with filling array of parts -see code below.

Macro stops at error on line:
ArrayOfParts(ArrayOfParts_size) = SelectedParts.Item(1).Value
"Object doesn't support this property or method"

is it even possible to create array of Part object's type?

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
Replies continue below

Recommended for you

Solution:
Code:
[b]Set[/b] ArrayOfParts(ArrayOfParts_size) = SelectedParts.Item(1).Value

Sometimes You are not smart enough to find such dummy mistake [bigglasses]

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
Hi luka,
I am having trouble getting my macro to Activate a node in the tree so that I can edit it. Any ideas?
 
My code:
ActiveSel.Add cattree.Products.Item(i) 'Selects My product
CATIA.StartCommand "Expand Selection"
SendKeys "1"
SendKeys "~"
doesn't work

This also doesn't work:
ActiveSel.Add cattree.Products.Item(i) 'Select VSYS_CHASSIS product
CATIA.StartCommand "Expand Selection"
hwndButtonOK = FindWindowEx(hwndExpSel, 0, "Button", "OK") 'Get handle to OK button
Foc = Putfocus(hwndExpTextbox) 'Put cursor in "Expand Selection" textbox
'SendKeys "1", True 'Choose single level expansion
lResult = SendMessage(hwndButtonOK, BM_CLICK, 0, 0) 'Press OK button
 
Code:
Sub CATMain()

AppActivate "CATIA V5"

Dim cmd As String

cmd = "wscript D:\sendKeys.vbs "
Call Shell(cmd)

End Sub

And D:\sendKeys.vbs code:

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")

WScript.sleep 200

WshShell.SendKeys "c:Expand Selection" + "{ENTER}", True

WScript.sleep 200
WshShell.SendKeys "4", True

WScript.sleep 200
WshShell.SendKeys "{ENTER}",True

Works well to me

Before You run macro, please select any object from tree

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
Didn't work for me...

I am writing in catvba - does that help?
 
Ok...got it to work, partially (thank you) - but it only expands the tree - it does not activate the selected node as a double-click does.

Any ideas on that?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor