What's new

Program to generate Hardware

vortec62

Member
Program to generate Hardware

I'm working on a program to automagically generate capscrews for use with AD. The ones from the library are fine but it takes forever to go get them.

I am working on two solutions at this time.

The first one involves modeling a 'generic' capscrew and writing a program to open it, change parameter values to produce the desired screw, then saving the result under a new filename.

The second approach is to have the program model the screw from scratch. This is the one I have spent the most time on so far.

I am using Visual Studio(Basic) .NET 2003. I'll try to post a zip file of my source files in the binaries section. I'll warn you ahead of time that I'm not a "real" programmer. I have a knack for beating on things 'til they do what I want though. The code is ugly nasty at this stage but there are comments in it. I've stolen bits of it from the API Help file and from this forum.

Tid-Bits:
The scales are all wrong...The resulting capscrew is supposed to be M8x1.25x30. There's some kind of cm-inch scale thing going on that I haven't explored yet.

It only generates 3 features so far...hex head, washer face, & body.

I have a spreadsheet full of capscrew data that I plan to use as source data for the program...it isn't linked in yet. The variable values for an M8x1.25x30 screw are coded in near the top of the source. The values came from the Machinery's Handbook 27th edition page 1541.

To run it...open AD and don't have any sessions going...push the "Generate Part" button.
 

Ralf

Alibre Super User


Excellent !!! This is a very good thing! I want much more of this.
:D
Many thanks make themselves further so ...

Ralf
Alibre Support Germany
 

indesign

Alibre Super User


:cry: Forgot I never upgraded to .net from the regular VB.

Guess I cant help on this one then. Good luck it looks like a very nice addon program.
 

vortec62

Member


I bet the code would work in the older versions of VB...

Try making a new form in you version of VB, create a button, then double click on it. This should create a section of code that will run when the button is clicked. You can then copy the appropriate section of code from the source files into your code. I did sort of the same thing in reverse to get some VB6 code working in VS.NET.
 

indesign

Alibre Super User


Little harder than that but I can at least start from the code and change all the math functions and probably the call functions.....Oh well modify away.
 

vortec62

Member


I worked on the scaling tonight and came up with the following observations/code...

Code:
        ' Figure out what MODEL units we're working with.
        ' Alibre default is cm. Why? Nobody uses cm...they use mm or inch!
        ' Suspect we'll only see different model units on imported stuff from other software.

        ' From an API point of view it doesn't seem to matter what the Display units are.
        ' If you send centimeter values to Alibre with the API they magically show up in
        '      Alibre scaled correctly for whatever display units the current session is using.
        ' If you read values from Alibre they show up as centimeter in the API.

        ' You can figure out what the ModelUnits and LengthDisplayUnits are for a session but
        '      you can't change them with the API for some reason.  It doesn't matter in that
        '      if your default Alibre setting is Feet your M8x30mm bolt will come out as 0.0984249ft long.
        '      
        ' It would be nice if you could set your display units to something appropriate with the API...
        ' i.e. if I make a metric screw I want to set it to mm. If I make a 1/2-13 screw I want to
        ' set it to inch.

        '        AD_UNITLESS    (1)
        '        AD_MILLIMETERS (200)
        '        AD_CENTIMETERS (201)
        '        AD_METERS      (202)
        '        AD_INCHES      (203)
        '        AD_FEET        (204)
        '        AD_DEGREES     (100)
        '        AD_RADIANS     (103)
        '        AD_KILOGRAMS   (400)
        '        AD_GRAMS       (401)
        '        AD_POUNDMASS   (402)

        objADDesignSession = objADSession
        objADProperties = objADDesignSession.DesignProperties

        ModelUnits = objADProperties.ModelUnits

        'MsgBox(\"ModelUnits = \" & ModelUnits)
        'MsgBox(\"DisplayUnits = \" & DisplayUnits)

        ' Convert everything to mm.
        ' Cuz that's what I like to use
        Select Case ModelUnits
            Case 200
                Mscale = 1              'would be 25.4 if program used inch calculations
            Case 201
                Mscale = 10             'would be 2.54 if program used inch calculations
            Case 202
                Mscale = 1000           'would be 0.0254 if program used inch calculations
            Case 203
                Mscale = 25.4           'would be 1 if program used inch calculations
            Case 204
                Mscale = (25.4 * 12)    'would be 1/12 if program used inch calculations
        End Select

        ' When sending data to Alibre divide by Mscale.
        ' When reading data from Alibre multiply by Mscale.
        '    WriteScale = 1 / Mscale
        '    ReadScale = Mscale
 

indesign

Alibre Super User


Never used VB to control another program before so I am new to some of the techniques. I started with your script in VB6 and beat it down to a couple errors now. I haven't been able to start the new file in Alibre yet so I will try to find a working example for VB6 from the forum. If anyone knows of a good one or would like to post the VB6 code let me know.
 

indesign

Alibre Super User


Big thanks to miles for the info on VB .NET express being free from microsoft. Now I can read your file and work directly with it. Do you have a newer version ready? If so could you post it and give me something to work on. Say of you want a certain routine added or just modified. I would be glad to help you get this going.

For instance would you like to add dialogs to ask for size,length, and type of screw. You could input the variables to draw either a hex head or a socket head and the screw size could be directly from the input instead of scaling. A .25" SHCS has a .25 tall head with a .19 socket by .19 deep (just an example).
 

vortec62

Member


I haven't done much to it other than the scaling stuff above. I'm not going to be able to spend any time on it for a few weeks because of holidays, vacations, etc.

Dialogs would be good. My original intent was to use data in a spreadsheet and generate a whole library of hardware in one shot.
 
Top