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!

StartCommand and SaveAs

Status
Not open for further replies.

MahPLM

Computer
Jun 22, 2016
6
TN
Hello,
I'm trying to write a macro to do "Generate CATPart from Product" then save the new part:

****
current_prod.Selection.Add current_prod.Product '


CATIA.StartCommand "Generate CATPart from Product"

CATIA.RefreshDisplay = True



For i = 1 To 100

SendKeys "{DELETE}"

Next i

SendKeys "NewPartName"



SendKeys "{ENTER}"

Sleep (7000) ' already declared : Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


CATIA.ActiveDocument.SaveAs current_prod.Path & "\NewCatPart"

****

As result , I have :
current_prod was saved in : current_prod.Path & "\NewCatPart"
the window "Generate CATPart from Product" displayed.
If i delete the two last lines of code, the generation works :(

Any help please ?
 
Replies continue below

Recommended for you

I hate send keys.

You need to create a new part, and them give it a partnumber and save it, Right?

Code:
Sub CATMain()

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As PartDocument
Set partDocument1 = documents1.Add("Part")

Dim product1 As Product
Set product1 = partDocument1.GetItem("Part1")

Dim strFilePath As String

strFilePath = CATIA.FileSelectionBox("Select the location to save the file, and insert it's part number", "*.CATPart", CatFileSelectionModeSave)

Dim char As Integer

char = Len(strFilePath)

Dim C As String
Dim D As String

Dim i As Integer

Do Until D = "\"
    i = i + 1
    C = Right(strFilePath, i)
    D = Left(C, 1)
    
Loop

Dim PN As String

PN = Right(strFilePath, i - 1)

PN = Replace(PN, ".CATPart", "")

product1.PartNumber = PN

partDocument1.SaveAs strFilePath

End Sub


So try this, for the new part. Later you can try to add the bodies from the several parts to this one.

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Hello Tiago Figueiredo,
I'am trying to save a part generated by the command "Generate CATPart from Product" .
Any help please ?
 
use the WIN API to find the window and to press OK button.

Google win API getwindow function, this is the entry point. From there you will have to search more.

As this is not a real CATIA topic I wont say more here, check and other net resources...

Eric N.
indocti discant et ament meminisse periti
 
I am not certain if this functionality is still valid, but it used to work once upon a time. Should also remove the need to use WINAPI or Sendkeys.

Code:
Set oProductDocument = CATIA.ActiveDocument
Set oProduct = oProductDocument.Product
Set oProd2Part = oProduct.GetItem("DECProductToPart")
oProd2Part.Run
sError = oProd2Part.GetError
Set oAllCATPart = oProd2Part.GetResult

--Doug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top