Can somebody please point me in the right direction for a macro that traverses a weldment cut list and for each profile in the cut list look at both ends of the profile to check their angles. Check if their angles are according to the same plane or twisted/rotated 90° and also if the angles are 45° or 135°
See also my first question about this but without API
https://forum.solidworks.com/message/1013032?commentID=1013032#comment-1013032
SolidworksApi/macros
what you probably need to do to approach this, is to use reference the triad coordinate system.
if your models are drawn with this in mind you can get the 3D angles relative to the coordinate system.
reference lines on the part, they have an axis in 2019 SOLIDWORKS API Help - LineParams Property (ICurve)
the adjacent part also has line params.
Take the two vectors and calculate the angle between them.
So if the line vector = 0,0,1 it is going positive to Z
If it is 0,0,-1 it is negative Z
1,0,0 is positive Y
So it could be .25,0.25,0.5 (they always add up to 1, that is what a normalized vector is) which has angles to each vector
To get the angle from one vector to another
create cartesian vectors
dim XVect as mathvector '(1,0,0)
Dim YVect as mathVector '(0,1,0)
Dim ZVect as MathVector '(0,0,1)
use the macro below to get started. this will get the angle between two edges. make sure they are lines.
sketch segments could work using sketchLine.GetCurve
2019 SOLIDWORKS API Help - GetCurve Method (ISketchSegment)
All you need are 3 numbers defining an axis to figure out angles to eachother or to the 3 Cartesian default vectors
Jacob Corder
www.cadsharp.com
Thank you for this .
I saw your reaction about this on an other post and realized that this is not simple but our draftsmen have to figure this our for every frame they draw and I would like to assist them with this with API so that they don't lose time and sleep over this. If you have further information about this and are willing to share I would be most grateful.
Frank
Hallo Frank,
That is a very steep hill to climb. A rectangular profile can have 10 possible permutations.
Gettting the angle is your least worry. How it relates to your profile sketch is the hard part.
Now throw in different style profile i.e. rounds and you can see how this will get out of hand quickly.
Cut saws that can do angled cuts in both horizontal and vertical plane have
often different cut limits per plane. That means some profile you need
to lay down with the long side while others you laydown short side.
Especially if you cut multiples...really hard task to organize.
The macro I have so far is attached.
Not really sure how to interpret the immediate window results. Are the 3 angles referring to X,Y and Z?
How can the twisted cuts be interpreted?
The macro does not traverse every profile and I can not find how to get the correct results by traversing through the whole body. Only the first 7 profiles are traversed and not all 8.
Planar faces are parallel if there normal are same or opposite.
Check if vNorm1(0), vNorm1(1) and vNorm1(2) is equal to vNorm2(0), vNorm2(1) and vNorm2(2) respectively or to -1*vNorm2(0), vNorm2(1), vNorm2(2) respectively.
I was using vNorm = swFace.Normal and the 3 values as result but don't know where to go from there
vNorm = swFace.Normal
Debug.Print "Normal = (" & vNorm(0) & ", " & vNorm(1) & ", " & vNorm(2) & ")"
Frank,
My bad there. It is Face2::Normal(). Please use that.
Hope it helps!!!
Rajat Jain
Thank you for helping.
Step 1: Got there
Step 2: Got there just now
Step 3: Can not find Surface::Normal (ISurface Interface)
Frank
Hello,
I am sure Jacob's suggestion shall help you in solving your problem. You can use the following tip to quickly get the cut faces: -
Hope it helps!!!
Rajat Jain
I will read up on those help files tomorrow
Thanks
you need to read up on these
2019 SOLIDWORKS API Help - Get Structural Member Body Sketch Segments Example (VBA)
2019 SOLIDWORKS API Help - IStructuralMemberFeatureData Interface Members
2019 SOLIDWORKS API Help - GetPathSegmentAt Method (IStructuralMemberFeatureData)
2019 SOLIDWORKS API Help - PathSegments Property (IStructuralMemberFeatureData)
get the structuralMemberFeatureData from the IFeauture whose GetTypeName = "WeldMemberFeat"
then get the data using IFeature:GetDefinition
well you need to get the body.
Evaluate all faces IBody2:GetFaces
determine what faces are the cut ones through analysis. there will be some logic you will figure out i'm sure.
take those 2 cut faces
get the angle between them.
But how do I get the cut face without selecting it manually?
In IFace2 I could not find a clue to getting the cut faces of each part
then what you need to do is
Take the cut faces.
use IFace;Normal to get its direction
Face1Vec =IMathUtiliity:CreateVector(IFace:Normal)
Face2Vec = IMathUtiliity:CreateVector(IFace:Normal)
Then you can pass those vectors to the same function GetAngleBetweenVectors.(Face1Vec,Face2Vec)
Jacob Corder
www.cadsharp.com
I will try to struggle through this. It looks like a way to get there but with my limited SW API knowledge the road is still looooong.
Myself I was thinking more in the line of traversing through the entire cut list and for each part in that cut list comparing the start and end face of the profile in relation to themselves and to the sketch line it originated from. But also this sounds a bit more like magic then reality to me now.
Thank you for your reaction