# Squaring List For Rectangular Blocks - Any Ideas?

• posted
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
• posted
I'm pretty sure you'll need a macro to do this, if you want it at all automated. Along those lines, IIRC, the API has an example for finding a precise bouding box with functions that find the extreme point of the model from a plane defined by a vector or some such. There is a bounding box function I think, but it's not precise.
For a non-automated method, I use reference dimensions in the part to measure the 3 overall sizes of the part, then link a custom property to the dimensions. We call this a stock size.
HTH
• posted
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
• posted
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?
• posted
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
"Seth Renigar" wrote in message news:RTxad.20650\$ snipped-for-privacy@twister.southeast.rr.com...
• posted
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.
• posted
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
and height custom property to the part
• posted
Wayne's revision works for me. Try it instead.
• posted
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
"Seth Renigar" wrote in message news:JHzad.20661\$ snipped-for-privacy@twister.southeast.rr.com...
• posted
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?
"Seth Renigar" wrote in message news:wnCad.20672\$ snipped-for-privacy@twister.southeast.rr.com...
• posted
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
in
• posted
Sorry Seth, I'm pretty ignorant with macro's. Hopefully somebody in here can sort it out.
M.T.
• posted
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 ----------
• posted
That's OK. I am ignorant with macros as well. It has been fixed already... Wayne Tiffany to the rescue.
• posted
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.
• posted
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
• posted
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
this several years ago.
than the "Custom" tab ?
• posted
The bug has bitten - I'm working on it. Please be patient.....
WT
• posted
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
• posted
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

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.