public void CreateByTwoPoints(PsPoint StartPoint, PsPoint EndPoint) { PsCreatePrimitive psCylinder = new PsCreatePrimitive(); PsCreatePrimitive psHead1 = new PsCreatePrimitive(); PsCreatePrimitive psHead2 = new PsCreatePrimitive(); PsCreatePrimitive psWasher = new PsCreatePrimitive(); PsCreatePrimitive psNut = new PsCreatePrimitive(); PsPolygon psNutPolygon = new PsPolygon(); PsVector psVector1 = new PsVector(); PsVector psVector2 = new PsVector(); PsVector psVector3 = new PsVector(); PsVector psVector = new PsVector(); psVector1.SetFromPoints(StartPoint, EndPoint); psVector2 = psVector.GetPerpendicularVector(psVector1); psVector3.SetFromCrossProduct(psVector1, psVector2); InsertPoint = StartPoint; KlemmLength = psVector1.Length; psVector1.Normalize(); psVector2.Normalize(); psVector3.Normalize(); ZAxis = psVector1; XAxis = psVector2; YAxis = psVector3; psCylinder.SetXYPlane(XAxis, YAxis); psCylinder.SetInsertPoint(InsertPoint); Length = Math.Round((KlemmLength + WasherThickness + NutHeight + LengthAdd + 0.375D) * 4, MidpointRounding.ToEven) / 4; psCylinder.CreateCylinder(Diameter / 2, Length); // Head PsVector XAxisNegative = new PsVector(); XAxisNegative = XAxis.Clone(); XAxisNegative.Invert(); psHead1.SetXYPlane(XAxisNegative, YAxis); psHead1.SetInsertPoint(InsertPoint); psHead1.CreateCylinder(HeadDiameter / 2, HeadHeight / 4); PsPoint head2InsertPoint = new PsPoint(); head2InsertPoint = InsertPoint.Clone(); head2InsertPoint.AddScaled(ZAxis, -1 * HeadHeight / 4); psHead2.SetXYPlane(XAxisNegative, YAxis); psHead2.SetInsertPoint(head2InsertPoint); psHead2.CreateCone(HeadDiameter / 2, HeadDiameter / 6, 0.75 * HeadHeight); // Washer psWasher.SetXYPlane(XAxis, YAxis); psWasher.SetInsertPoint(EndPoint); psWasher.CreateCylinder(WasherOuterDiameter / 2, WasherThickness); // Nut PsPoint nutInsertPoint = new PsPoint(); nutInsertPoint = EndPoint.Clone(); nutInsertPoint.AddScaled(ZAxis, WasherThickness); psNutPolygon.createPolygon(6, NutKeySize / 2, false); psNut.SetXYPlane(XAxis, YAxis); psNut.SetPolygon(psNutPolygon); psNut.SetInsertPoint(nutInsertPoint); psNut.CreateExtrusion(NutHeight, 0D, 0D); // Unite all int cylinderId = psCylinder.ObjectId; int head1Id = psHead1.ObjectId; int head2Id = psHead2.ObjectId; int washerId = psWasher.ObjectId; int nutId = psNut.ObjectId; int[] ids = { head1Id, head2Id, washerId, nutId }; PsCutObjects psUniteObjects = new PsCutObjects(); psUniteObjects.SetObjectId(cylinderId); PsTransaction psTransaction = new PsTransaction(); foreach (int i in ids) { psUniteObjects.SetAsBooleanCut(i); psUniteObjects.SetSubBodyType(SubBodyType.kAddBody); psUniteObjects.CreateLogicalLink = false; psUniteObjects.Apply(); psTransaction.EraseLongId((long)i); psTransaction.Close(); } PsUnits psUnits = new PsUnits(); PsMaterialTable psMaterialTable = new PsMaterialTable(); PsObjectProperties psObjectProperties = new PsObjectProperties(); psObjectProperties.Name = Type + " " + psUnits.ConvertToText(Diameter) + "x" + psUnits.ConvertToText(Length) + " " + MaterialName; psObjectProperties.Material = psMaterialTable.get_MaterialIndexFromName(MaterialName); psObjectProperties.ColorIndex = Color; PartListFlag = true; psObjectProperties.PartListFlag = PartListFlag; PartFamilyClassIndex = -1; psObjectProperties.FamilyClass = PartFamilyClassIndex; psObjectProperties.Length = Length; psObjectProperties.writeTo(cylinderId); PsPrimitive psPrimitive = new PsPrimitive(); psTransaction.GetObject((long)cylinderId, PsOpenMode.kForWrite, ref psPrimitive); psPrimitive.writeProps(psObjectProperties); psTransaction.Close(); }
public int CreateAnchorCode111(PsPoint Point1, PsPoint Point2) { PsCreatePrimitive psCylinder = new PsCreatePrimitive(); PsCreatePrimitive psWasher = new PsCreatePrimitive(); PsCreatePrimitive psNut = new PsCreatePrimitive(); PsPolygon psNutPolygon = new PsPolygon(); PsVector psVector1 = new PsVector(); PsVector psVector2 = new PsVector(); PsVector psVector3 = new PsVector(); PsVector psVector = new PsVector(); psVector1.SetFromPoints(Point1, Point2); psVector2 = psVector.GetPerpendicularVector(psVector1); psVector3.SetFromCrossProduct(psVector1, psVector2); InsertPoint = Point1; psVector1.Normalize(); psVector2.Normalize(); psVector3.Normalize(); ZAxis = psVector1; XAxis = psVector2; YAxis = psVector3; PsVector XAxisNegative = new PsVector(); XAxisNegative = XAxis.Clone(); XAxisNegative.Invert(); //Cylinder PsPoint CylinderInsertPoint = new PsPoint(); CylinderInsertPoint = InsertPoint.Clone(); CylinderInsertPoint.AddScaled(ZAxis, -1 * (Length - Embedment - PartThickness)); psCylinder.SetXYPlane(XAxis, YAxis); psCylinder.SetInsertPoint(CylinderInsertPoint); psCylinder.CreateCylinder(Diameter / 2, Length); // Washer psWasher.SetXYPlane(XAxisNegative, YAxis); psWasher.SetInsertPoint(InsertPoint); psWasher.CreateCylinder(WasherOuterDiameter / 2, WasherThickness); // Nut PsPoint nutInsertPoint = new PsPoint(); nutInsertPoint = InsertPoint.Clone(); nutInsertPoint.AddScaled(ZAxis, -1 * WasherThickness); psNutPolygon.createPolygon(6, NutKeySize / 2, false); psNut.SetXYPlane(XAxisNegative, YAxis); psNut.SetPolygon(psNutPolygon); psNut.SetInsertPoint(nutInsertPoint); psNut.CreateExtrusion(NutHeight, 0D, 0D); // Unite all int cylinderId = psCylinder.ObjectId; int washerId = psWasher.ObjectId; int nutId = psNut.ObjectId; int[] ids = { washerId, nutId }; PsCutObjects psUniteObjects = new PsCutObjects(); psUniteObjects.SetObjectId(cylinderId); PsTransaction psTransaction = new PsTransaction(); foreach (int i in ids) { psUniteObjects.SetAsBooleanCut(i); psUniteObjects.SetSubBodyType(SubBodyType.kAddBody); psUniteObjects.CreateLogicalLink = false; psUniteObjects.Apply(); psTransaction.EraseLongId((long)i); psTransaction.Close(); } PsUnits psUnits = new PsUnits(); PsObjectProperties psObjectProperties = new PsObjectProperties(); psObjectProperties.Name = Type + " " + psUnits.ConvertToText(Diameter) + "x" + psUnits.ConvertToText(Length); psObjectProperties.ColorIndex = Color; psObjectProperties.PartListFlag = PartListFlag; psObjectProperties.FamilyClass = PartFamilyClassIndex; psObjectProperties.Length = Length; psObjectProperties.writeTo(cylinderId); PsPrimitive psPrimitive = new PsPrimitive(); psTransaction.GetObject((long)cylinderId, PsOpenMode.kForWrite, ref psPrimitive); psPrimitive.writeProps(psObjectProperties); psTransaction.Close(); ObjectId = cylinderId; return(ObjectId); }
private void InsertOne(string StiffenerLabel, string StiffenerMaterial, double StiffenerThickness, int StiffenerPositionIndex) { List <int> objs = new List <int>(); PsUnits psUnits = new PsUnits(); PsShapeInfo psShapeInfo = new PsShapeInfo(); PsGeometryFunctions geometryFunctions = new PsGeometryFunctions(); PsPoint psInsertionPoint = new PsPoint(); PsPoint psStartPoint = new PsPoint(); PsPoint psEndPoint = new PsPoint(); PsPoint psMidLineInsertionPoint = new PsPoint(); PsPolygon psStiffenerPolygon = new PsPolygon(); PsCreatePlate psStiffinerPlateRight = new PsCreatePlate(); PsCreatePlate psStiffinerPlateLeft = new PsCreatePlate(); PsMatrix psMatrixRight = new PsMatrix(); PsMatrix psMatrixLeft = new PsMatrix(); PsSelection arg1 = new PsSelection(); arg1.SetSelectionFilter(SelectionFilter.kFilterShape); int num1 = arg1.PickObject("Please select W shape beam..."); //returns object id if (num1 > 0) { PsSelection arg2 = new PsSelection(); int num2 = arg2.PickPoint("Select insertion point", CoordSystem.kWcs, psInsertionPoint); if (num2 == 1) { psShapeInfo.SetObjectId(num1); int num3 = psShapeInfo.GetInfo(); //gets object property values psStartPoint = psShapeInfo.MidLineStart; psEndPoint = psShapeInfo.MidLineEnd; psMidLineInsertionPoint = geometryFunctions.OrthoProjectPointToLine( psInsertionPoint, psShapeInfo.MidLineStart, psShapeInfo.MidLineEnd); double shapeLength = geometryFunctions.GetDistanceBetween(psStartPoint, psEndPoint); if (geometryFunctions.GetDistanceBetween(psMidLineInsertionPoint, psStartPoint) <= shapeLength && geometryFunctions.GetDistanceBetween(psMidLineInsertionPoint, psEndPoint) <= shapeLength) { psShapeInfo.SetStiffenerType(0, 0.75, 0); psStiffenerPolygon = psShapeInfo.getStiffenerPolygon(psInsertionPoint); psStiffinerPlateRight.SetFromPolygon(psStiffenerPolygon); psStiffinerPlateRight.SetThickness(StiffenerThickness); psMatrixRight = psShapeInfo.MidLineUcs; psMatrixLeft = psMatrixRight.Clone(); psMatrixLeft.MirrorAtLine(psStartPoint, psEndPoint); psStiffinerPlateRight.SetInsertMatrix(psMatrixRight); psStiffinerPlateRight.Create(); objs.Add(psStiffinerPlateRight.ObjectId); CommonFunctions.MoveObject( (long)psStiffinerPlateRight.ObjectId, ref psStartPoint, ref psMidLineInsertionPoint); psStiffinerPlateLeft = psStiffinerPlateRight; psStiffinerPlateLeft.SetInsertMatrix(psMatrixLeft); psStiffinerPlateLeft.Create(); objs.Add(psStiffinerPlateLeft.ObjectId); CommonFunctions.MoveObject( (long)psStiffinerPlateLeft.ObjectId, ref psStartPoint, ref psMidLineInsertionPoint); objIds = objs.ToArray(); //test MessageBox.Show(psShapeInfo.ShapeName); } else { MessageBox.Show("Selected point is out of beam", "Oops...", MessageBoxButtons.OK); } } } }