×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

StartCommand and SaveAs

StartCommand and SaveAs

StartCommand and SaveAs

(OP)
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 ?

RE: StartCommand and SaveAs

I hate send keys.

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

CODE --> vba

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:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: StartCommand and SaveAs

(OP)
Hello Tiago Figueiredo,
I'am trying to save a part generated by the command "Generate CATPart from Product" .
Any help please ?

RE: StartCommand and SaveAs

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 https://stackoverflow.com/ and other net resources...

Eric N.
indocti discant et ament meminisse periti

RE: StartCommand and SaveAs

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 --> VBA

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

--Doug

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!


Resources