I can manually create a part, and assign it a mate reference in Solidworks. I can record the VB code necessary to perform this action in code. I can manually create an assembly file and insert the part and get the mate to work correctly. But, when I try to repeat this action in code, the mate doesn't seem to be recognized. It shows up in the "Feature Tree", just does want to "click" in. Any ideas?
Here's a thought...I had a similar problem with inserting the part into the assembly. I could do it manually, but in code, something seemed to be missing. The recorded macro did not show the missing step...namely, that the part file had to be open. When I opened the file, in code, then inserted it, everything worked. I had to "guess" what was missing. My suspicion is that something is "missing" in the recorded code, but I have no idea what.
Any code writers out there run into this?
Solidworks
Can you share your codes and files to test.
Yes I can. To keep it simple, I am only showing relevant code. I am building a steel water tank, say, 20 feet diameter and 15 feet high. It will be built in 3 pieces, each 20 feet diameter by 5 feet tall and .25 inch thick. So I draw a circle, offset the thickness of the metal, and extrude the height of the ring. Then we will stack the rings and weld them. I set a mate reference for the top edge of the lowest ring and a same-name mate reference on the bottom edge of the second ring...coincident. Just a thought, if I select the inside edge on one mate and the outside edge on the other mate, a coincident mate would not work...maybe a concentric/parallel? Not sure what edge I selected. I will investigate.
'open a new part file
Set Part = swApp.NewPart
'draw a circle
Set skSegment = Part.SketchManager.CreateCircle(0, 0, 0, radius, 1, 0#)
'offset it to the outside (shellthickness should be a positive number if offset to the outside)
boolstatus = Part.SketchManager.SketchOffset(shellthickness, False, True, False, False, True)
'extrude it up
Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, ringheight, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, True, True, True, 0, 0, False)
'create a mate reference
boolstatus = Part.Extension.SelectByID2("", "EDGE", 0, radius, ringheight, True, 1, Nothing, 0)
Set myFeature = Part.FeatureManager.InsertMateReference(matename, Nothing, swMateReferenceType_Coincident, 0, Nothing, 0, 0, Nothing, 0, 0)
'now, save the part
longstatus = Part.SaveAs3(rootpath & partname & ".SLDPRT", 0, 2)
'now, close the file
Set Part = Nothing
After some confusion on my part (no pun intended), I have confirmed that I am selecting the inside radius edge on all mates, so everything should line up. It makes the most sense to me to try to choose a coincident mate. This would not require any further alignment.
Still, the parts do not want to stick together in the assembly.
why not try to create some references like its axis of the cylindrical tank shell. use the ref. axis and end edge to mate it.