Squaring List For Rectangular Blocks - Any Ideas?

Discussion in 'SolidWorks' started by Sean-Michael Adams, Oct 10, 2004.

  1. Here's my situation / wish:

    I have an assembly of parts that I need to square up blocks for. All
    the blocks have rectangular (no turned parts) envelopes with some
    features in them (holes, a cutout, etc).

    Does anyone have any tools or ideas on how one might use the BOM or
    mass props or whatever to determine the bounding cubes (ok
    rectangleoids or whatever) to determine a squaring list?

    I'm looking for something like the cut list on the weldments. Mind
    you, this is not a weldment, so some of the modeling pre-requisites
    for a cut list are not in the parts, nor do I want them to be.

    Simplistically, every part has a bounding cube and I would like to
    find a way to take an assembly, insert a table with the right
    properties and get an XYZ squaring list for the parts. I can
    presently generate this list by measuring the parts:I'm looking for a
    way to get this list automatically.

    Thanks for any hints, tips or ideas.

    :)

    SMA
     
    Sean-Michael Adams, Oct 10, 2004
    #1
  2. Sean,

    Here's a macro that measures the part and adds .015 stock to the block size.
    Sorry , I can't remember who wrote it, but it works by adding a length, width and height custom property to the part
    which can then be manipulated however you like.

    HTH,

    M.T.

    Sub main()
    Set swApp = CreateObject("SldWorks.Application")
    Set Part = swApp.ActiveDoc
    corners = Part.GetPartBox(False)
    length = Abs(corners(3) - corners(0)) + 0.015 'X axis
    height = Abs(corners(4) - corners(1)) + 0.015 ' Z axis
    width = Abs(corners(5) - corners(2)) + 0.015 ' Y axis
    'Remove existing properties
    retval = Part.DeleteCustomInfo2("", "Length")
    retval = Part.DeleteCustomInfo2("", "Width")
    retval = Part.DeleteCustomInfo2("", "Height")
    'Add latest values
    retval = Part.AddCustomInfo3("", "Length", swCustomInfoNumber, length)
    retval = Part.AddCustomInfo3("", "Width", swCustomInfoNumber, width)
    retval = Part.AddCustomInfo3("", "Height", swCustomInfoNumber, height)
    End Sub
     
    Malcolm_Tempt, Oct 11, 2004
    #2
  3. Sean-Michael Adams

    Seth Renigar Guest

    I am having problems with this.

    I don't know how to edit macros very well (like none). But I thought that
    this one sounded like it would be useful so I tried to make it work. I
    clicked Tools>Macro>New and gave it a name (LWH.swp). I then highlighted
    everything from Sub main() down, deleted it, and pasted the macro from your
    message. Is this correct? When I try to run it, I get this error:

    Compile error:
    Argument not optional

    What have I done wrong?

    --
    Seth Renigar
    Emerald Tool and Mold Inc.
    (Remove "SpamFree_" from my address)


     
    Seth Renigar, Oct 11, 2004
    #3
  4. Try this it works here.

    WT

    Sub main()

    Dim Length As Variant
    Dim Height As Variant
    Dim Width As Variant
    Dim Corners As Variant
    Dim retval As Boolean

    Set swApp = CreateObject("SldWorks.Application")
    Set Part = swApp.ActiveDoc
    Corners = Part.GetPartBox(False)
    Length = Abs(Corners(3) - Corners(0)) + 0.015 'X axis
    Height = Abs(Corners(4) - Corners(1)) + 0.015 ' Z axis
    Width = Abs(Corners(5) - Corners(2)) + 0.015 ' Y axis
    'Remove existing properties
    retval = Part.DeleteCustomInfo2("", "Length")
    retval = Part.DeleteCustomInfo2("", "Width")
    retval = Part.DeleteCustomInfo2("", "Height")
    'Add latest values
    retval = Part.AddCustomInfo3("", "Length", swCustomInfoNumber, Length)
    retval = Part.AddCustomInfo3("", "Width", swCustomInfoNumber, Width)
    retval = Part.AddCustomInfo3("", "Height", swCustomInfoNumber, Height)
    End Sub


     
    Wayne Tiffany, Oct 11, 2004
    #4
  5. Sean-Michael Adams

    Seth Renigar Guest

    Thanks Wayne. That worked. It did exactly as I expected.

    I tried playing with it to get it to do something a little different, but
    failed miserably. Is there an easy way to modify this to only create 1
    custom property so that it reads something like "1.234 x 5.678 x 9.123"
    rounded to a 3 place decimal?

    If so, it might be cool to set this up as a macro feature.

    --
    Seth Renigar
    Emerald Tool and Mold Inc.
    (Remove "SpamFree_" from my address)


     
    Seth Renigar, Oct 11, 2004
    #5
  6. Thanks for the code. Here is the problem I have. When I save and run
    the macro I have an error in the line that begings with WIDTH. Do you
    know why?

    Thanks
     
    Rob Rodriguez, Oct 11, 2004
    #6
  7. Sean-Michael Adams

    Seth Renigar Guest

    Wayne's revision works for me. Try it instead.

    --
    Seth Renigar
    Emerald Tool and Mold Inc.
    (Remove "SpamFree_" from my address)


     
    Seth Renigar, Oct 11, 2004
    #7
  8. Try this. If you want to change the decimal places, change the value at the
    end of the Length, Height, Width lines. I don't know how this will parse
    out in the message, so watch the long line right before End Sub. I also
    commented out (rather than deleting) the individual properties in case you
    want to use them later.

    WT

    Sub main()

    Dim Length As Double
    Dim Height As Double
    Dim Width As Double
    Dim Corners As Variant
    Dim retval As Boolean

    Set swApp = CreateObject("SldWorks.Application")
    Set Part = swApp.ActiveDoc
    Corners = Part.GetPartBox(False)
    Length = Round(Abs(Corners(3) - Corners(0)) + 0.015, 3) 'X axis
    Height = Round(Abs(Corners(4) - Corners(1)) + 0.015, 3) ' Z axis
    Width = Round(Abs(Corners(5) - Corners(2)) + 0.015, 3) ' Y axis
    'Remove existing properties
    'retval = Part.DeleteCustomInfo2("", "Length")
    'retval = Part.DeleteCustomInfo2("", "Width")
    'retval = Part.DeleteCustomInfo2("", "Height")
    retval = Part.DeleteCustomInfo2("", "BoundingSize")
    'Add latest values
    'retval = Part.AddCustomInfo3("", "Length", swCustomInfoNumber, Length)
    'retval = Part.AddCustomInfo3("", "Width", swCustomInfoNumber, Width)
    'retval = Part.AddCustomInfo3("", "Height", swCustomInfoNumber, Height)
    retval = Part.AddCustomInfo3("", "BoundingSize", swCustomInfoText, Height &
    " x " & Width & " x " & Length)
    End Sub
     
    Wayne Tiffany, Oct 12, 2004
    #8
  9. Ok I tried Wayne's code and it works. Thanks Wayne. I have another
    question. I would like the units to be set to a specific format. The
    current macro result would read in inches (ex 24.00000) and I would like it
    to read in feet and inches (ex 2'-0"). Is there a way of doing this?





     
    Rob Rodriguez, Oct 12, 2004
    #9
  10. I just played with the macro a bit and it appears that the "False" of
    Part.GetPartBox(False) does change the units to the user units - sort of.
    If you set it to true, you get meters. If you set it to false, you get
    inches, or feet, or millimeters, but it doesn't appear to make a difference
    if your user units are set to decimal or fraction. Either way you get
    decimal. I suppose you could write in a converter to parse it out to a
    fraction, but is it worth the effort? The later version that I posted did
    set the values to 3 places, and also combined them into one variable.

    I will check with API support to see if I am missing something here.

    WT


     
    Wayne Tiffany, Oct 12, 2004
    #10
  11. Sorry Seth, I'm pretty ignorant with macro's. Hopefully somebody in here can sort it out.

    M.T.
     
    Malcolm_Tempt, Oct 12, 2004
    #11
  12. Sean-Michael Adams

    rocheey Guest

    Just a quick heads up: as long as you need the ORTHAGONAL bounding
    box, SWX returns ok... but sometimes the smallest cube does not align
    orthagonally.


    You could always set your units.. or try the following macro. Pass it
    the
    decimal inches, and the required DENOMINATOR of the fractional inches,
    ie;

    debug.Print DecimalToFeetInches(24.125,64)
    returns 2'-0 8\64"


    debug.Print DecimalToFeetInches(24.125,0)
    returns 2'-0"


    '----------- snip here ------------ snip here ----------

    Function DecimalToFeetInches(DecimalLength As Double, Denominator As
    Integer) As String
    ' converts decimal inches to feet/inches/fractions

    Dim intFeet As Integer
    Dim intInches As Integer
    Dim intFractions As Double
    Dim FractToDecimal As Double
    Dim remainder As Double
    Dim tmpVal As Double



    ' compute whole feet
    intFeet = DecimalLength \ 12
    remainder = DecimalLength - (intFeet * 12)
    tmpVal = CDbl(Denominator)

    ' compute whole inches
    intInches = Int(remainder)
    remainder = remainder - intInches


    ' compute fractional inches
    ' check for division by zero
    If Not (remainder = 0) Then
    If Not (Denominator = 0) Then
    FractToDecimal = 1 / tmpVal
    If FractToDecimal > 0 Then
    intFractions = Int(remainder / FractToDecimal)
    End If
    End If
    End If

    ' format output
    DecimalToFeetInches = LTrim$(Str$(intFeet)) & "'-"
    DecimalToFeetInches = DecimalToFeetInches &
    LTrim$(Str$(intInches))
    If intFractions > 0 Then
    DecimalToFeetInches = DecimalToFeetInches & " "
    DecimalToFeetInches = DecimalToFeetInches &
    LTrim$(Str$(intFractions))
    DecimalToFeetInches = DecimalToFeetInches & "\" &
    LTrim$(Str$(Denominator))
    End If

    DecimalToFeetInches = DecimalToFeetInches & Chr$(34)

    End Function

    '----------- snip here ------------ snip here ----------
     
    rocheey, Oct 12, 2004
    #12
  13. Sean-Michael Adams

    Seth Renigar Guest

    That's OK. I am ignorant with macros as well. It has been fixed already...
    Wayne Tiffany to the rescue.

    --
    Seth Renigar
    Emerald Tool and Mold Inc.
    (Remove "SpamFree_" from my address)


     
    Seth Renigar, Oct 12, 2004
    #13
  14. <SNIP>

    Wayne,

    Your macro is exactly what I was looking for when I first enquired about this several years ago.
    Do you know if the output can be sent to the "Config Specific" tab rather than the "Custom" tab ?

    Thanks again,

    M.T.
     
    Malcolm_Tempt, Oct 12, 2004
    #14
  15. Yes, you are correct that the bounding box dimensions are aligned with the
    principle axes, therefore if the part is not a "best fit" to them, the
    bounding box may not actually be the best size. Good comment!

    The DecimalToFeetInches function was what I was thinking of and sort of
    hoped someone had already written it. It certainly could be added to the
    macro to perform that function. I received a very nice email from API
    supt - here it is. So, bottom line is that if you want the fractions, we
    need to add the function. I'll add that as I get a chance.

    WT


    Hi Wayne,

    In general, APIs return only decimals, as the VARIANT data type is not
    suitable for returning fractions. This is just the way that the API works.
    Thanks,

    Steve Mycynek
    API Support Engineer
     
    Wayne Tiffany, Oct 12, 2004
    #15
  16. Yes it can be added to a config specific property. What would you like to
    call it? At the point of running the macro, it would grab the current
    config and apply the property to that one. Acceptable?

    WT

     
    Wayne Tiffany, Oct 12, 2004
    #16
  17. The bug has bitten - I'm working on it. Please be patient.....

    WT
     
    Wayne Tiffany, Oct 13, 2004
    #17
  18. This is great Wayne. I can wait as long as it takes. This macro would be a
    huge help to me and I'm sure others here. I know nothing about writing
    macros but it's become clear to me that they can be a huge time saver. I
    guess I'll have to learn.

    Rob
     
    Rob Rodriguez, Oct 13, 2004
    #18
  19. AARRGGHH!!! I HATE FRACTIONS!!!

    I don't know why I agreed to do this - I hate fractions. This is what I now
    get:
    1'-7 6\8" x 0'-3 8\8" x 3'-3 4\8"

    When I find the distances, I add a small amount (.015" or so) and then if
    the user units are FeetInches, they have to be converted. So into the
    routine to parse it into the separate categories, all the while pulling out
    integer values and dealing with the remainder. So, you get to the point of
    how many integer denominators do you have (like 5/8"), but if there is still
    some left over, you can't just drop it because then the bounding box could
    be smaller than the object. So if there is still a remainder, I added 1 to
    the number of them, thereby making 6/8", thereby necessitating another
    routine to check if it can be divided down farther. Thennnnnn, if it
    happens to be 8/8" or so, up has to go the inches. Butttt, what if it then
    makes 12"?? You get the picture. I hate fractions - so stupid.

    WT
     
    Wayne Tiffany, Oct 13, 2004
    #19
  20. I did a search through the VB Help for "fraction" and didn't come up with
    anything useful. I hate fractions. Tell me quickly - what is the order -
    largest to smallest - 47/64, 5/8, 17/32. Unless you recognize the values
    from using them all the time, you can't look at them and know. Yes, you can
    convert to common denominators and then do it, but why not use decimal to
    start with. Then they are real numbers. And,,,, don't get me started on
    rounded off fractions - you don't have any idea what the number really is -
    merely a close guess. Stupid!

    WT
     
    Wayne Tiffany, Oct 13, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.