Generate NC Output Interactively

Javier Fernández

Generate NC Output Interactively
how can i generate the NC output code with a Macro?

I don't know how can i start...

thanks a lot!

Kimmo Takala

RE: Generate NC Output Interactively
(in response to Javier Fernández)
do you mean (APT->macro->nc-code)?

Bryan Carpio Felsher

RE: Generate NC Output Interactively
(in response to Javier Fernández)
If you don't haven't bought and installed ICAM, IMS, or CENIT, then you can't do it through Catia directly.

But, if you DO have a post-processor, then you can manipulate this file:

C:\Program Files\Dassault Systemes\B19\win_b64\code\bin\MfgBatchCmd.bat

It is the batch program that gets run when you post aptsource out in "Batch mode."

You could simply add a call in the batch program to your "outside" executable post-processor.

This is what is inside the MfgBatchCmd.bat program:

@echo on
echo %1 %2 %3 %4 %5 %6 %7 %8

MfgBatch %1 %2 %3 %4 %5 %6 %7 %8

For an explanation of the variables called, you could add a line: echo %1 %2 %3 %4 %5 %6 %7 %8 > "c:\temp.text"

or something like that. You really have to understand how to play around with batch programs, fto5 files, etc...too much for me to explain in a post here on the forum, but if you understand computers a little, this should get you started...

Samarinder Singh Cheema

RE: Generate NC Output Interactively
(in response to Javier Fernández)
I have made my Apt2CNC macro in VB. Because batch mode is very slow.

Bryan Carpio Felsher

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Yup, that's why I never use it....it's just so slow. Most of the time, I just want to post aptsource, and if I do want to post the G-code, I have a newish posting tool I wrote just for myself in Basic, and it sends all messages from the post-processor executable to a text file, which is handy to quick-scan for messages, errors, unwinds, etc...Mine also kind of looks like yours, I think...where you can click a button and open the summary, listing, log, nc, and/or aptsource file in the text editor of your choice. Or open the pptable, or you can also send the nc code to an XYZABC limits report tool, send the aptsource to PRO-APT, send aptsource/NC file to my SetupSheetHelper.exe program, and some other stuff.

Kind of cool to write these custom tools for post-processing, but you really want to write them yourself, so you can customize it exactly how you specifically want it, and for the specific executables you have on your workstation or network. My program would have to be really customized to be good for each individual user. I have kind of a generic version, that I give to guys who buy AZPost from me. Apt2CNC looks cool, for the user that wants to post G-code directly from Catia with a post, other than the DS sponsored ones. I like the idea of creating user configurable batch program linked to buttons in the GUI. Then, the user can make calls to whatever he wants, and rename the buttons. Sort of like what Larry did with MFGWorkBench.

RICHARD STEINER

RE: Generate NC Output Interactively
(in response to Javier Fernández)
I use GPOST here and use the shell command to execute a .bat file to post-process the .aptsource. The VBA looks similar to CATV but we always use the same "fixture" so I didn't have to deal with that. So basically the macro prompts you for, among other things, the operation(s) you want to post, left or right part or both, which machine, and whether you want to download the machine code to the server. It also invokes Vericut and loads an STL file if you wish.

The only thing I didn't like was that I couldn't figure out how to go to all the tabs in the "Generate NC Output Interactively" window and set all the buttons and check boxes to my own default. In other words I had to make sure the users had the settings the same and I had to do it manually for each user. I don't remember now why that was important because I worked on it quite a few years ago but it always bugged me that I couldn't get that figured out. Anyhow, once everyone had the buttons and check boxes the same the output and the macro turned out great.

Samarinder Singh Cheema

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Posted By WICHARD on 15 Dec 2010 03:42 AM
I use GPOST here and use the shell command to execute a .bat file to post-process the .aptsource. The VBA looks similar to CATV but we always use the same "fixture" so I didn't have to deal with that. So basically the macro prompts you for, among other things, the operation(s) you want to post, left or right part or both, which machine, and whether you want to download the machine code to the server. It also invokes Vericut and loads an STL file if you wish.

The only thing I didn't like was that I couldn't figure out how to go to all the tabs in the "Generate NC Output Interactively" window and set all the buttons and check boxes to my own default. In other words I had to make sure the users had the settings the same and I had to do it manually for each user. I don't remember now why that was important because I worked on it quite a few years ago but it always bugged me that I couldn't get that figured out. Anyhow, once everyone had the buttons and check boxes the same the output and the macro turned out great.

Hi Richard,

You can assign a command button in your macro for the following command to control settings for the tabs interactively. It will launch the dialog box and you can change/modify the settings and then just close it, then continue with the rest of the macro.

CATIA.StartCommand "Generate NC Code Interactively"

Best Regards,
Samarinder


RICHARD STEINER

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Samarinder,

Thanks for the comment - I just got assigned two projects so I'll work on that the next time I get a chance.

Noah Bettin

RE: Generate NC Output Interactively
(in response to Javier Fernández)
What is the point of batch mode and why is it so slow anyway? I never use it either but it could be useful as a hook to do custom post processing if it weren't such a slug.

Samarinder/Bryan would either of you like to share some of your macro for doing this? If not, no worries.

Samarinder Singh Cheema

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Sub AptCNC()

        oProcessDoc = CATIA.ActiveDocument
        Dim Selection = oProcessDoc.Selection
        Dim InputObjectType(0)
        InputObjectType(0) = "AnyObject"

        Dim Status = Selection.SelectElement2(InputObjectType, "Select the Program", False)

        If (Status = "Cancel") Then
            Selection.Clear() : Exit Sub
        End If

        Dim mySelection = Selection.Item(1).Value

        strFile = strFile & "_" & mySelection.Name

        outputGen = Selection.Item(1).Value
        outputGen.InitFileGenerator("APT", strFile & ".aptsource", genData)
        outputGen.RunFileGenerator(genData)
        genData.ResetAllModalValues

    End Sub

Noah Bettin

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Thanks Samarinder,
I have the same code pretty much. But when I execute it my part disappears from the screen. The tree is still there but the part is just gone. Ever seen that happen?

'generate APT
Dim myMfgAPTGenerator As ManufacturingAPTGenerator = Nothing
myMfgAPTGenerator = myMfgProgram

Dim myMfgGeneratorData As ManufacturingGeneratorData = Nothing
myMfgAPTGenerator.InitFileGenerator("APT", My.Settings.WorkingFolder & myProcessTemplate & ".aptsource", myMfgGeneratorData)
myMfgAPTGenerator.RunFileGenerator(myMfgGeneratorData)
myMfgGeneratorData.ResetAllModalValues()

'read the APT to a text box
Dim fileContents As String
fileContents = fileRead(My.Settings.WorkingFolder & myProcessTemplate & ".aptsource")
RichTextBox1.Text = fileContents

Deepak Manuel, SME - NC Manufacturing

RE: Generate NC Output Interactively
(in response to Javier Fernández)
You can also use the FT05 utility with a batch file. Attached is a zip file with some sample batch files..

with best regards
Deepak Manuel
Dassault Systemes
Attachments

  • FT05.zip (1.2k)

Noah Bettin

RE: Generate NC Output Interactively
(in response to Javier Fernández)
In looking at the documentation for the mfgOutputGenerator it seems that we can output APT from various starting points. I want to output APT for all programs in a setup into one APT file. But the method fails for any object other than a single program. Does anyone know how to output APT by the other objects listed in the documentation?

Generation of NC code can start from the Process, Setup, Program or an Activity.
Parameters:
iFormat , Format of the output file : "APT", ...
iFileName , Output file name
oData , iData contains all the information about the generated NC code.

I've tried setting "myMfgAPTGenerator = myMfgSetup" instead of "myMfgProgram" but this fails.
'generate APT using mfgAPTGenerator
Dim myMfgAPTGenerator As ManufacturingAPTGenerator = Nothing myMfgAPTGenerator = myMfgSetup

Dim myMfgGeneratorData As ManufacturingGeneratorData = Nothing
myMfgAPTGenerator.InitFileGenerator("APT", My.Settings.WorkDir & myMfgSetup.Name & ".aptsource", myMfgGeneratorData)
myMfgAPTGenerator.RunFileGenerator(myMfgGeneratorData)
myMfgGeneratorData.ResetAllModalValues()


I've also tried using the MfgOutputGenerator on a MfgSetup instead and the method doesn't fail. But it doesn't save the output to disk either. Is there a trick to that?
'generate APT using MfgOutputGenerator
Dim myMfgOutputGenerator As ManufacturingOutputGenerator = Nothing
myMfgOutputGenerator = myMfgSetup

Dim myMfgGeneratorData As ManufacturingGeneratorData = Nothing
myMfgOutputGenerator.InitFileGenerator("APT", My.Settings.WorkDir & myMfgSetup.Name & ".aptsource", myMfgGeneratorData)
myMfgOutputGenerator.RunFileGenerator(myMfgGeneratorData)

Bryan Carpio Felsher

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Thanks for the sample batch programs Deepak. Very cool trick. I have done something similar by editing the MFG batch program...but batch mode is still just too slow, so I don't use it.

Noah Bettin

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Has anybody else found that this method fails in R20? ManufacturingAPTGenerator
I have some scripts which still work for R19 but fail in R20 at the point of saving the APT; myMfgAPTGenerator.RunFileGenerator(myMfgGeneratorData)

Dave Frank

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Hi Noah,

Try calling your B partner.
Sometimes the API name change in a new release, and some maintaince is required on VB macros when using new rel.

HTH
Dave

Samarinder Singh Cheema

RE: Generate NC Output Interactively
(in response to Javier Fernández)
Everything is OK here. I didn't see any problem running this macro in R20.

niko gall

RE: Generate NC Output Interactively
(in response to Samarinder Singh Cheema)

Hi there!

 

i saw this cool thread and suddenly used it for my use,here is what i did. it takes pokets and holes both as prismaticMachiningArea-feautes and uses them in pocketing operations. then it computes the tolpath of every operation. then it makes Apt-nc code.

my question now: is it possible,to get in addition to the apt code the collisions-text file?

 

load a setup in prismatic area,start global feauture-recognition,then run makro.note that there are some things in the part to get safetyplane and origin.

 



Sub catmain()


Dim MfgDoc1 As Document
Set MfgDoc1 = CATIA.ActiveDocument

'----------Process-Definition---------------------------------------------

Dim ActivityRef As AnyObject
Set ActivityRef = MfgDoc1.GetItem("Process")

'-------------Setup1-Def,hier auch die ganzen erzeuger-methoden rein,"setPart.."-----------


Dim Setup1 As ManufacturingSetup
Dim childs As Activities
Dim child As Activity

If (ActivityRef.IsSubTypeOf("PhysicalActivity")) Then
 Dim quantity
  Set childs = ActivityRef.ChildrenActivities
  quantity = childs.Count

  If quantity <= 0 Then
    Exit Sub
  End If
   Dim NumberOfSetup
   NumberOfSetup = 0

Dim I
  For I = 1 To quantity
          Set child = childs.Item(I)
          If (child.IsSubTypeOf("ManufacturingSetup")) Then
                Set Setup1 = child
                NumberOfSetup = NumberOfSetup + 1
                Exit For
          End If
  Next

End If

If NumberOfSetup <= 0 Then
     Exit Sub
End If



'----------------------Produkt Def als kontext für Setup-Einrichtung,sehr wichtiger schritt für alles BearbOPS,also PROD
'ist das gesamte Setup mit fitures,und NC das bearbeitbare set aus rohteil und fertigteil---------------


Dim Prod As Product
Set Prod = Setup1.Product


Dim NC As Product

For I = 1 To Prod.Products.Count
      
    If Prod.Products.Item(I).PartNumber = "NC_Geometry" Then
        Set NC = Prod.Products.Item(I)
           
            Exit For
  
    End If
     
    Next
'------------------DesignPart und wichtige elemente herholen-----------------------------

Dim pa As PartDocument
Set pa = NC.ReferenceProduct.Parent

Dim part As part
Set part = pa.part

Dim bod As Bodies
Set bod = part.Bodies

Dim des As AnyObject
Set des = bod.GetItem("Final")

Dim sto As AnyObject
Set sto = bod.GetItem("Stock")
        
Dim ebene As AnyObject
Set ebene = des.HybridShapes.GetItem("Oben")

Dim ursprung As AnyObject
Set ursprung = des.HybridShapes.GetItem("Point.1")


'---------------------Setup einrichten--------------------------------

Call Setup1.MachiningAxisSystem.SetOriginPoint(ursprung, NC)
Call Setup1.MachiningAxisSystem.SetOriginXDirection(1, 0, 0)
Call Setup1.CreateMachine("Mfg3AxisMachine")
Call Setup1.Machine.set_DefaultValues

Call Setup1.SetDesignPart(des, NC)
Call Setup1.SetStock(sto, NC)
Call Setup1.SetSafetyPlane(ebene, NC)
                          

'Dim view As ManufacturingView
'Set view = Setup1.GetManufacturingView

           
'----------------Programm Def----------------------

Dim dasProgramm As ChildrenActivities
Set dasProgramm = Setup1.ChildrenActivities

Dim Prog As ManufacturingProgram
Set Prog = dasProgramm.GetItem("Manufacturing Program.1")

Dim manu 'As ManufacturingOperation

Dim featu As ManufacturingFeatures
Set featu = view.ManufacturingFeatures


Dim PMA As ManufacturingFeature
Dim ob As AnyObject


For Each PMA In featu


    If TypeName(PMA) = ("ManufacturingPrismaticMachiningArea") Then
            Set ob = PMA
                Set manu = Prog.AppendOperation("Pocketing", 1)
                       Call manu.SetFeature(ob)
                     
                            If manu.IsGeometricallyAccessibleOnSetup(Setup1) Then
                                    Call manu.SetTool("End Mill D10 Rc0")
                                      Call manu.AddMotionToAPlane("Approach", 1, ebene, NC)
                                      
                                            Dim oEndPoint(3)
                                            Call manu.GetTrajectoryEndPointCoord(oEndPoint)
                                           
                        End If
       End If
    Next
   

Dim aptgen As ManufacturingAPTGenerator
Set aptgen = Prog

Dim MGD As ManufacturingGeneratorData
Set MGD = Nothing

Call aptgen.InitFileGenerator("APT", "C:\NC-Code\hier.aptsource", MGD)
Call aptgen.RunFileGenerator(MGD)
Call MGD.ResetAllModalValues


'Dim sel1 As Selection
'Set sel1 = CATIA.ActiveDocument.Selection
'sel1.Clear
'sel1.Search "NC Manufacturing.Manufacturing Program.Name=Manufacturing Program.1"


'CATIA.StartCommand ("Start Video Simulation using Tool Path")
'Pause = 3

'sel1.Clear
 
End Sub

 

 

Jeff Alan Turczynski

RE: Generate NC Output Interactively
(in response to Noah Bettin)

Based on some of the earlier posts in this thread, I was able to figure out how to ouput an aptsource file for an entire program.  I also added some additional logic into the macro so it would automatically launch the aptsource file in Notepad after it generates the file.  I would now like to be able to output a single MO or multiple MO's into one aptsource file.  Does anyone know if its possible?

Surgin AA

RE: Generate NC Output Interactively
(in response to Deepak Manuel, SME - NC Manufacturing)

Dear Deepak Manuel

  I'm very lucky to see your suggestions on using "FT05" utility with a batch file to realize "generate NC output interactively". It‘s very useful!

thanks a lot!

yours sincerely

  Surgin 

2020/08/27

Attachments

  • attach.jpg (45.7k)
Edited By:
Surgin AA[Subscriber Members] @ Aug 28, 2020 - 08:37 AM (Asia/Taipei)

Surgin AA

RE: Generate NC Output Interactively
(in response to Deepak Manuel, SME - NC Manufacturing)

Hello everyone!

Thanks a lot!, Mr. Deepak Manuel explaining  how to use the FT05 utility with a batch file.

I generate the NC code with the batch mode.but it's very very slowly compare with the interactively Mode.

who can explain this problem?thanks a lot!

 

@echo on

echo %1 %2 %3 %4 %5 %6 %7 %8

MfgBatch %1 %2 %3 %4 %5 %6 %7 %8

Edited By:
Surgin AA[Subscriber Members] @ Jan 22, 2021 - 08:50 AM (Asia/Taipei)