×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Selecting a CATPart or Sub-product to work in that document

Selecting a CATPart or Sub-product to work in that document

Selecting a CATPart or Sub-product to work in that document

(OP)
I have a VBscript that works well in a catpart but it fails in a catproduct. I want to be able to select the catpart or a sub-product within the top-product to make it active and/or set the partdocument from the list of documents within the product. In the code below, assuming I don't know the name of document "PartName.CATPart", I need to have code to select the tree item and Set partDoc1 from that selection.

Sub CATMain()

Set doc1 = CATIA.Documents

'--------------
Set partDoc1 = doc1.Item("PartName.CATPart")
>>> name not known, so I need to replace this line
>>> with selection process below
'--------------

InputObjectType(0)= "AnyObject"

Set oSelA = doc1.Selection

oSelA.clear

Result = oSelA.SelectElement(InputObjectType, "Select Tree Item", False)

If Result = "Cancel" Then
MsgBox ("Command Canceled")
Exit Sub
End If

Set partDoc1 = oSelA.Item(1)
>>>> this is where I'm stuck. I can't get the document
>>>> out of the selection to set partDoc1

Set part1 = partDoc1.Part

Set hybridShapeFactory1 = part1.HybridShapeFactory

RE: Selecting a CATPart or Sub-product to work in that document

Hi, You need to use the .Value property of the selected object, e.g. Set partDoc1 = oSelA.item(1).Value.

You should also use .SelectElement2 rather than SelectElement if you want the code to run in R11 onwards.

RE: Selecting a CATPart or Sub-product to work in that document

(OP)
Tried that. The '.Value' gives a reference not a part document. The next line fails. I need to extract the part document from the selected tree item ( part or sub product )
to make active in whick to work. The 'Set partDoc1 = oSelA.item(1).Value.name' shows the name of the instance....'part1.1', its document would be 'part1.CATPart'.

RE: Selecting a CATPart or Sub-product to work in that document

See if this can give you what you are after...

    Set doc1 = CATIA.ActiveDocument
    InputObjectType = Array("Part", "Product")
    Set osela = doc1.Selection
    osela.Clear
    Result = osela.SelectElement2(InputObjectType, "Select Part", False)
    If Result = "Cancel" Then
        MsgBox ("Command Canceled")
        Exit Sub
    End If
    If osela.Item(1).Type = "Product" Then
        ' do some sub product code
        Debug.Print "Selected Product"
    ElseIf osela.Item(1).Type = "Part" Then
        ' do some part code
        Debug.Print "Selected Part"
    End If


If it is a product you need to use the PartNumber not the Name and you should be able to construct the appropriate document name from that, e.g.

set oDoc = CATIA.Documents.Item(selecteditem.PartNumber & ".CATProduct")

or something like that. However, you need to ensure that people don't select the 'Product node' for a part in the assembly tree (the node above the part in the tree). If they select the wrong node then the code assumes it is a product and not a part and you would get an error. You just need to put in some simple error trapping or limit them to just parts if this is possible.


RE: Selecting a CATPart or Sub-product to work in that document

(OP)
From your suggestion, I ended up with the following code example that lets me select the Part in the tree and aquires the .CATPart document.

Within a CATProduct, it works well up until the 'COPY' line. It errors with : Selected element not allowed for this operation!

It works all the way through within just a CATPart.

Sorry to pick your brain, but, got any ideas?

Code:
Language="VBSCRIPT"

Sub CATMain()

Dim InputObjectType(0)
Dim InputDocType(0)
InputDocType(0) = "Part"

Set ActiveDoc = CATIA.ActiveDocument

' Prompt to select destination part document if a Product is active

Set oActDocSel = ActiveDoc.Selection
InputDocType(0) = "Part"
Result = oActDocSel.SelectElement2(InputDocType, "Select CATPart", False)
msgbox result

If Result = "Cancel" Then
MsgBox ("Command Canceled")
Exit Sub
End If

Set DestinationDoc = CATIA.Documents.Item(oActDocSel.Item(1).value.name & ".CATPart")

oActDocSel.Clear

Set oSelB = DestinationDoc.Selection

InputObjectType(0)= "Face"
Result = oSelB.SelectElement2(InputObjectType, "Select a face", False)

If Result = "Cancel" Then
MsgBox ("Command Canceled")
Exit Sub
End If

oSelB.copy <---- Error:Selected element not allowed for this operation!

msgbox "copied"

End Sub

RE: Selecting a CATPart or Sub-product to work in that document

Hi,

Try changing your script to:


Dim InputObjectType(0)
Dim InputDocType(0)
InputDocType(0) = "Part"

Set ActiveDoc = CATIA.ActiveDocument

' Prompt to select destination part document if a Product is active

Set oActDocSel = ActiveDoc.Selection
InputDocType(0) = "Part"
Result = oActDocSel.SelectElement2(InputDocType, "Select CATPart", False)
MsgBox Result

If Result = "Cancel" Then
MsgBox ("Command Canceled")
Exit Sub
End If

Set DestinationDoc = CATIA.Documents.Item(oActDocSel.Item(1).Value.Name & ".CATPart")

oActDocSel.Clear

InputObjectType(0) = "Face"
Result = oActDocSel.SelectElement2(InputObjectType, "Select a face", True)

If Result = "Cancel" Then
MsgBox ("Command Canceled")
Exit Sub
End If

oActDocSel.Copy '<---- Error:Selected element not allowed for this operation!

MsgBox "copied"


You should perform the copying using the top level document selection object (in this case the active document).

RE: Selecting a CATPart or Sub-product to work in that document

(OP)
Thanks 'AHay'. This put me in the right direction. The program works in a catproduct and a catpart now.

I had to select the face first from a foreign CATPart within the Product, copy to clipboard , aquire the destination CATPart by selection, and Paste the Externally Linked Surface in the destination.

The only problem I have now is I want the program to check the selected Face properties to see if it is already in the selected destination CATPart and not foreign before I choose to copy/paste. In the full (larger) program, the face is used as a reference for creating normal lines through points.

Resulting Sample code that works:

Language="VBSCRIPT"
Sub CATMain()

Dim InputObjectType(0)
Dim InputDocType(0)

InputDocType(0) = "Part"
Set ActiveDoc = CATIA.ActiveDocument
Set ActDocSel = ActiveDoc.Selection

InputObjectType(0)= "Face"
Result = ActDocSel.SelectElement2(InputObjectType, "Select a Face ", False)

If Result = "Cancel" Then
    MsgBox ("Command Canceled")
    Exit Sub
End If

ActDocSel.copy
ActDocSel.Clear

'Select Destination CATPart

InputDocType(0) = "Part"
Result = ActDocSel.SelectElement2(InputDocType, "Select CATPart", False)

If Result = "Cancel" Then
    MsgBox ("Command Canceled")
    Exit Sub
End If

Set WorkDoc = CATIA.Documents.Item(ActDocSel.Item(1).value.name & ".CATPart")

WorkDoc.part.InWorkObject = WorkDoc.part
ActDocSel.PasteSpecial "CATPrtResult"
WorkDoc.part.update

Set Ref1 = ActDocSel.item(1).value

End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close