I insert a bounding box into a part, how to get coordinates of all 8 pionts?
My recored macro use
BoundingBox = Part.FeatureManager.InsertGlobalBoundingBox
to get the bounding box.
Your 'Boundingbox' variable is (i assume) a "Feature".
in this case, you can call double boxCorners = Boundingbox.GetBox()
boxCorners will be an array with 6 entries, being X0, Y0, Z0, X1, Y1, Z1 respectively; giving you two edges of the diagonal of the bounding box.
in other words: you got the highest and lowest values for X, Y and Z in this bounding box.
now, your corner points are:
Thanks for reply. I tried getbox method, looks not work:
Dim BoundingBox As Object
Set BoundingBox = Part.FeatureManager.InsertGlobalBoundingBox(swGlobalBoundingBoxFitOptions_e.swBoundingBoxType_BestFit, False, True, longstatus)
boxCorners = BoundingBox.GetBox()
I don't see the you defining 'boxCorners' in that snippet; this might be my fault, i wrote the line as it would be in C# (which i mainly write in)
Dim boxCorners as new double()
Set boxCorners = BoundingBox.GetBox()
I work on VBA, still trying to make my Visual Studio work.
Anyway, my code is like this:
This will give error that requires object.
If I change that to object, then it will give "run time error 91 vba object variable or with block variable not set"
Ah, now i see; i blame the inconsistency of the API...
The method of calling differs between components, models and features...
That call works for me. make sure that you include the '()' at the end of 'Double', this indicates the difference between a single number and a collection of numbers.
As an aside: you might not want to put all your "Dim" commands at the top (outside of "Main"), especially when you do progress to Visual Studio.
That spot is for information that every macro will use (like "swApp"); things that are just for this process should be inside of "Main"
Thanks for reply and your tips. I only have some experinece with Excel VBA. I only modified few Solidoworks VBA example before.
My VBA doesn't allow me to use both "new double" and "new double()", in both case, it will give me identifier error.
Only way to stop it give me identifier error is to just use "Dim boxCorners As Double". However, it will give me complie error: need object.
By the way, do you have any reference about how to setup VS enviroment? I have VS 2015 community version, SW2019 API installed, but in the new project interface, i could not find Silidworks template.
Retrieving data ...