Advertisement
mostafa90

Create 3DSweep

Feb 7th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.82 KB | None | 0 0
  1.  //  Profile of the
  2.         static List<XYZ> _profilepoints = new List<XYZ>()
  3.         {
  4.             new XYZ (-0.082020997, 0.000000000, 0.000000000),
  5.             new XYZ(0.410104987, 0.000000000, 0.000000000),
  6.             new XYZ (-0.082020997, 0.984251969, 0.000000000),
  7.             new XYZ (-0.082020997, 0.000000000, 0.000000000),
  8.             new XYZ (0.246062992, 0.984251969, 0.000000000),
  9.             new XYZ(-0.082020997, 0.984251969, 0.000000000),
  10.             new XYZ (0.410104987, 0.000000000, 0.000000000),
  11.             new XYZ(0.410104987, 0.820209974, 0.000000000),
  12.             new XYZ (0.246062992, 0.984251969, 0.000000000),
  13.             new XYZ(0.410104987, 0.820209974, 0.000000000)
  14.       };
  15.  
  16.  
  17.  
  18. static public Document m_doc;
  19.  
  20.         public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  21.         {
  22.             UIApplication uiapp = commandData.Application;
  23.             UIDocument uidoc = uiapp.ActiveUIDocument;
  24.             m_doc = uidoc.Document;
  25.  
  26.             IList<Reference> refs = null;
  27.             refs = uidoc.Selection.PickObjects(ObjectType.Edge);
  28.  
  29.             Transaction tr = new Transaction(m_doc, "curvemodel");
  30.             tr.Start();
  31.  
  32.             ReferenceArray rArr = new ReferenceArray();
  33.            
  34.  
  35.             foreach (Reference r in refs)
  36.             {
  37.                 Options op = new Options();
  38.                 op.ComputeReferences = true;
  39.  
  40.                 Element e = m_doc.GetElement(r.ElementId);
  41.  
  42.                 GeometryElement ge = e.get_Geometry(op);
  43.                 foreach (GeometryObject go in ge)
  44.                 {
  45.                     Solid solid = go as Solid;
  46.                     foreach (Edge edg in solid.Edges)
  47.                     {
  48.                         if (edg.Reference.ConvertToStableRepresentation(m_doc) == r.ConvertToStableRepresentation(m_doc))
  49.                         {
  50.  
  51.                            
  52.  
  53.                             SketchPlane plan = SketchPlane.Create(m_doc, edg.GetFace(0).Reference);
  54.                                                      
  55.                             ModelCurve mc = m_doc.FamilyCreate.NewModelCurve(edg.AsCurve(), plan);
  56.  
  57.                             rArr.Append(mc.GeometryCurve.Reference);
  58.  
  59.                            
  60.                         }
  61.  
  62.                     }
  63.                 }
  64.  
  65.  
  66.  
  67.             }
  68.             tr.Commit();
  69.  
  70.             Transaction t = new Transaction(m_doc, "Create Sweep2d");
  71.             t.Start();
  72.          
  73.             createcurbs(m_doc, rArr);       //Create 3D sweep
  74.  
  75.             t.Commit();
  76.  
  77.  return Result.Succeeded;
  78.  
  79.         }
  80.  
  81.  
  82. ///3Dsweep Method
  83.         public void createcurbs(Document doc, ReferenceArray path3D)
  84.         {
  85.             FamilyItemFactory factory = doc.FamilyCreate;
  86.            
  87.  
  88.             IList<Curve> cel = new List<Curve>();
  89.  
  90.             for (int i = 0; i < _profilepoints.Count; i = i + 2)
  91.             {
  92.                 try
  93.                 {
  94.                     cel.Add(Line.CreateBound(_profilepoints[i], _profilepoints[i + 1]) as Curve);
  95.  
  96.                 }
  97.                 catch (Exception)
  98.                 {
  99.  
  100.                     cel.Add(Line.CreateBound(_profilepoints[i], _profilepoints[0]) as Curve);
  101.  
  102.                 }
  103.  
  104.  
  105.             }
  106.  
  107.             CurveArray sweepArray = DrawLoops.convert2Array(cel);  //method to arrange Curves inorder to create a contiguous loop and then convert it to Array
  108.  
  109.  
  110.             CurveArrArray swerarar = new CurveArrArray();
  111.             swerarar.Append(sweepArray);
  112.  
  113.             SweepProfile swpprof = doc.Application.Create.NewCurveLoopsProfile(swerarar);       // this is the profile
  114.  
  115.  
  116.  
  117.             // Create sweep solid
  118.          
  119.             Sweep sweep3D = factory.NewSweep(true, path3D, swpprof, 0, ProfilePlaneLocation.Start);
  120.  
  121.  
  122.     }
  123.          
  124.     }
  125.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement