Macro dev help required for part builder wizard

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
arieclaassens
Posts: 3
Joined: Thu Sep 26, 2013 8:35 pm

Macro dev help required for part builder wizard

Post by arieclaassens »

Background: I have a friend that makes a lot of custom mechanical components, which requires that he spend a lot of time in AutoCAD creating the part and its drawing sheet. A lot of the work is repetitive and can be automated by using a macro or set of macros in FreeCAD, combining one or more basic shapes to create a new object. This will make it easier for non-technical staff to create the new object and also to stop using AutoCAD.

I've been working unsuccessfully for the last two weeks (on a part time basis, as and when time allows) on building a macro that will let me do the following:

1. Open a base brush shape file, set the view to axometric and fit object inside the viewport (Done)
2. Ask the user if he/she wants to import another base shape to create a new brush shape. If yes, import the selected shape and use the appropriate boolean operation to create the new object.
3. Repeat process until user has selected all the base shapes to use to create the new shape. Continue to next step.
3. Ask the user for the dimensions of the new object (length, width, height), as well as any cut outs,curvatures, etc. and resize the object according to specifications.
4. Ask the user to select all the cable mount positions - selected from a predefined list of locations
5. Ask the user to select the terminal type and specify the length of the cables running between the cable mount positions and terminals.
6. Generate the completed object's drawing sheet and populate the cartridge, as per http://www.freecadweb.org/wiki/index.ph ... artoucheFC

I've dug around on the old and new wiki, copied a number of macros and code snippets to try and build up a working,reliable solution, but my lack of Python programming knowledge (and time) and non-existent CAD background makes this very difficult to accomplish.

I would like to know if you could point me to the right people to discuss this with, or let me know if there is an existing solution that I can adapt with minimal tinkering.

Any and all help will be highly appreciated.

Thanks a stack in advance.

Arie
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: Macro dev help required for part builder wizard

Post by jreinhardt »

arieclaassens wrote: I would like to know if you could point me to the right people to discuss this with, or let me know if there is an existing solution that I can adapt with minimal tinkering.
I think there is no better place to discuss such matters than right here. I do not know of any existing solution.
arieclaassens wrote:Background: I have a friend that makes a lot of custom mechanical components, which requires that he spend a lot of time in AutoCAD creating the part and its drawing sheet. A lot of the work is repetitive and can be automated by using a macro or set of macros in FreeCAD, combining one or more basic shapes to create a new object. This will make it easier for non-technical staff to create the new object and also to stop using AutoCAD.

I've been working unsuccessfully for the last two weeks (on a part time basis, as and when time allows) on building a macro that will let me do the following:

1. Open a base brush shape file, set the view to axometric and fit object inside the viewport (Done)
2. Ask the user if he/she wants to import another base shape to create a new brush shape. If yes, import the selected shape and use the appropriate boolean operation to create the new object.
3. Repeat process until user has selected all the base shapes to use to create the new shape. Continue to next step.
3. Ask the user for the dimensions of the new object (length, width, height), as well as any cut outs,curvatures, etc. and resize the object according to specifications.
4. Ask the user to select all the cable mount positions - selected from a predefined list of locations
5. Ask the user to select the terminal type and specify the length of the cables running between the cable mount positions and terminals.
6. Generate the completed object's drawing sheet and populate the cartridge, as per http://www.freecadweb.org/wiki/index.ph ... artoucheFC

I've dug around on the old and new wiki, copied a number of macros and code snippets to try and build up a working,reliable solution, but my lack of Python programming knowledge (and time) and non-existent CAD background makes this very difficult to accomplish.
Can you show your code and describe where you are stuck? Otherwise it is very difficult to help.

Greetings
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
arieclaassens
Posts: 3
Joined: Thu Sep 26, 2013 8:35 pm

Re: Macro dev help required for part builder wizard

Post by arieclaassens »

Thanks for your reply, jreinhardt.

I'd prefer to outsource the project to a competent FreeCAD developer, as I lack the time to learn Python and cannot seem to track down the full coding language constructs - I'm looking for the equivalent of PHP's manual, e.g. http://php.net/manual/en/book.mcrypt.php, which will show me what commands are available and how to invoke them. I can help myself very well when it comes to programming in HTML, CSS, PHP, ASP, ColdFusion and bash, but I'm preparing to start a distance learning course through a UK university next week, which will consume a lot of my time, along with my normal work commitments.

I initially used a line-by-line task execution approach to the problem, but I would prefer to switch to an OOP model, as I think it will make it a lot easier to modify the functionality of the wizard and also to maintain the code during the FreeCAD development process. In frustration, I deleted the VM I worked on yesterday and started over with a new macro, based once again on code from the wiki. Below is the current code for the start of the process.

Code: Select all

from PyQt4 import QtCore, QtGui
import FreeCAD
import Part
import ImportGui

Gui.activateWorkbench("PartWorkbench")
# Select .IGS Brush file to be imported
filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open Your BASE brush shape file','*.IGS')
f1=str(filename)
ImportGui.insert(f1,"Unnamed")
Gui.activeDocument().activeView().viewAxometric()
Gui.SendMsgToActiveView("ViewFit")

#Load another file?


class p():

    def proceed(self):
        #FreeCAD.Console.PrintError("Importing Scaled Airfoil") # this was a bit noisy :}
        try:
		  # Select .IGS Brush file to be imported
		  filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open Your ADDITIONAL brush shape file','*.IGS')
		  f1=str(filename)
		  ImportGui.insert(f1,"Unnamed")
        except:
            FreeCAD.Console.PrintError("Error, not a valid .IGS file\n")

        self.close()

    def close(self):
        self.dialog.hide()
	   #Fire off code to start next phase - connector points, followed by connector wire lengths and type of connectors

    def __init__(self):
        self.dialog = None
        self.s1 = None
	   #Fire off brush selector popup
        bselector(p)

p()

def bselector(self):
	 # Make dialog box and get the scale size
        self.dialog = QtGui.QDialog()
        self.dialog.resize(260,100)
        self.dialog.setWindowTitle("Brush Part Builder Wizard")
        la = QtGui.QVBoxLayout(self.dialog)
        t1 = QtGui.QLabel("Do you want to add another shape?")
        la.addWidget(t1)
        self.s1 = QtGui.QLineEdit()
        #la.addWidget(self.s1)
        okbox = QtGui.QDialogButtonBox(self.dialog)
        okbox.setOrientation(QtCore.Qt.Horizontal)
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        la.addWidget(okbox)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), proceed)
        #QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), close)
	   #QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
        self.dialog.show()
        self.dialog.exec_()
I'm trying to move the popup window to a class of its own, so that I can keep calling it until the user has selected all the existing brush shapes that want to use to create the new object with. (The files are all IGES files created from the DWG files currently used by my friend - he's a very proficient AutoCAD user, but not a coder).

Thanks a stack in advance.

Regards,

Arie.
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: Macro dev help required for part builder wizard

Post by jreinhardt »

Hi,

I thought I had answered, but the post got lost somehow. So here is a short version of it again:

1) Python has very good documentation here:

http://docs.python.org/2/index.html

The tutorial has many examples and is very useful if you are not a experiences python programmer, the library reference covers the standard library. The corresponding FreeCAD documentation (although much less detailed and complete) is here:

http://freecadweb.org/api/

The python language reference is a overview over all constructs, but I find it rather formal and not very useful for practical coding.

2) Qt has a special class for Wizards, it might be useful to look into that: http://pyqt.sourceforge.net/Docs/PyQt4/qwizardpage.html

3) I would try to first approach the different aspects of your task separately, so try to get a wizard up and running in PyQt (without FreeCAD), and try to do your CAD stuff in FreeCAD with the python console without a Wizard. If you know how to do these two things, you can put it together.

Greetings

Johannes
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
arieclaassens
Posts: 3
Joined: Thu Sep 26, 2013 8:35 pm

Re: Macro dev help required for part builder wizard

Post by arieclaassens »

Hi Johannes, thanks for the links to the API (and QWizardPage class), that was primarily what I was looking for; dunno how I missed the link (probably a mental classification thing).

I've broken the project down into sets of macros on paper and by using the code completion functionality in the console window, managed to make a lot of progress.

I'll pop back in again if I need further assistance.

Much appreciated.

PS: If anyone is interested in assisting with the project in exchange for a cash reward, let me know and we can draw something up on a site like freelancer.com.

Regards,

Arie.
Post Reply