.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

about DrawJig

1 REPLY 1
Reply
Message 1 of 2
师兄
1331 Views, 1 Reply

about DrawJig

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections;
using Autodesk.AutoCAD.Publishing;
namespace ClassLibrary
{
public class CQSRJGClass : DrawJig
{

private Point3d point0;
public static double radius = 1.0;
public static double L1 = 5.0;
public static double L2 = 10.0;
public static double bulg = 1.0 - Math.Sqrt(2.0);
public static double r1 = 0.5;
public static double r2 = 1.5;
public static double L3 = 4.0;
public Polyline pline;
private Point3d startPosition;
private Point3d currentPosition;
// private Region reg;
private Solid3d solid;
//private Solid3d oldsolid=new Solid3d();
// private Circle cir1=new Circle();


private Editor ed;
private Transaction tm;
private BlockTableRecord btr;

[CommandMethod("DRJG")]
public void test()
{
ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
//ed.WriteMessage(Application.Version.ToString());
PromptPointResult point = ed.GetPoint("\n选择二极管第一引脚点:");
if (point.Status==PromptStatus.OK)
{
point0 = point.Value;
tm = db.TransactionManager.StartTransaction();
//ed.Document.LockDocument();

try
{
double x = point0.X;
double y = point0.Y;
double z = point0.Z;
Point2d[] array = new Point2d[6];
array.SetValue(new Point2d(x, y), 0);
array.SetValue(new Point2d(x, y + L1), 1);
array.SetValue(new Point2d(x + radius, y + L1 + radius), 2);
array.SetValue(new Point2d(x + radius + L2, y + L1 + radius), 3);
array.SetValue(new Point2d(x + L2 + 2.0 * radius, y + L1), 4);
array.SetValue(new Point2d(x + L2 + 2.0 * radius, y), 5);
pline = new Polyline(6);
pline.SetDatabaseDefaults();
for (int i = 0; i < array.GetLength(0); i++)
{
pline.AddVertexAt(i, (Point2d)array.GetValue(i), 0.0, 0.0, 0.0);
}
startPosition = new Point3d(x + L2 + 2.0 * radius, y, z);
pline.SetBulgeAt(1, bulg);
pline.SetBulgeAt(3, bulg);
solid=new Solid3d();
//solid.SetDatabaseDefaults();

btr = (BlockTableRecord)tm.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, true);
btr.AppendEntity(pline);
tm.AddNewlyCreatedDBObject(pline, true);
btr.AppendEntity(solid);
tm.AddNewlyCreatedDBObject(solid,true);
//tm.Commit();

PromptResult promptResult = ed.Drag(this);
// if(promptResult.Status== PromptStatus.OK)
// {
// pline.Draw();
// solid.Draw();
// }
tm.Commit();
}
catch(Autodesk.AutoCAD.Runtime.Exception e)
{
ed.WriteMessage(e.Message);
}
catch(System.Exception e)
{
ed.WriteMessage("系统错误: "+e.Message);
//ed.WriteMessage(e.Message);
tm.Dispose();

}


finally
{
tm.Dispose();
}

}
}
protected override bool WorldDraw(WorldDraw draw)
{

draw.Geometry.Draw(solid);

draw.Geometry.Draw(pline);


return true;
}
// protected override void ViewportDraw(ViewportDraw draw)
// {
// draw.Geometry.Draw(solid);
// draw.Geometry.Draw(pline);
// }

protected override SamplerStatus Sampler(JigPrompts prompts)

{
//GC.Collect();
//ed.UpdateScreen();
JigPromptOptions jigPromptOptions = new JigPromptOptions();
jigPromptOptions.BasePoint=point0;
jigPromptOptions.Cursor=CursorType.RubberBand;
jigPromptOptions.UseBasePoint=true;
jigPromptOptions.Message="\n选择终点: ";
Point3d value = prompts.AcquirePoint(jigPromptOptions).Value;
currentPosition = value;
if(currentPosition.DistanceTo(point0)>L2+2*radius&&currentPosition !=startPosition)
{
double X =currentPosition.X;
double Y = currentPosition.Y;
double z = currentPosition.Z;
pline.SetPointAt(5, new Point2d(X, Y));
pline.SetPointAt(4, new Point2d(X, Y + L1));
pline.SetPointAt(3, new Point2d(X - radius, Y + L1 + radius));
//pline.Draw();

DBObjectCollection paths = new DBObjectCollection();

Circle cir1 = new Circle(point0, new Vector3d(0.0, 1.0, 0.0), r1);

paths.Add(cir1);
DBObjectCollection regs = Region.CreateFromCurves(paths);
IEnumerator enumerator = regs.GetEnumerator();
enumerator.Reset();
enumerator.MoveNext();
if (enumerator.Current.GetType().Name=="Region")
{
Region reg=(Region)enumerator.Current;
try{
solid.CleanBody();
solid.ExtrudeAlongPath(reg,pline,0);
//solid.Close();
//btr.AppendEntity(solid.AcadObject);
//tm.AddNewlyCreatedDBObject(solid.AcadObject,true);


reg.Dispose();
cir1.Dispose();
// solid.Draw();
}
catch(Autodesk.AutoCAD.Runtime.Exception e)
{
ed.WriteMessage(e.Message);
return SamplerStatus.NoChange;
}
}

startPosition=currentPosition;
return SamplerStatus.OK;
}else
{
return SamplerStatus.NoChange;
}
}
}
}

 

I use  these codes to realize my dragging,but when i just drag ,the solid can not  display  colour third dimension graph 

Another problem is this program always throw error, the error message is C++Run-time errors...

 

can you help me?

 

1 REPLY 1
Message 2 of 2
jeff
in reply to: 师兄

Check out this site http://spiderinnet1.typepad.com/blog/

 

It has alot of post about jigs and wizard to create them automaticlly

You can also find your answers @ TheSwamp

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost