先建一个名为“1”的块
-
- using System;
- using Autodesk..DatabaseServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.ApplicationServices;
- using System.Reflection;
- using System.IO;
- using System.Collections;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.GraphicsInterface;
- namespace TlsCad
- {
- public class BlockRefJig:EntityJig
- {
- Point3d mPosition,mAnglePnt;
- Vector3d mNormal;
- double mAngle;
- int mPromptCounter;
- DynamicDimensionDataCollection m_dims;
- public BlockRefJig(Vector3d vec,ObjectId id):base(new BlockReference(new Point3d(0,0,0),id))
- {
- mPosition=new Point3d(0,0,0);
- mNormal=vec;
- mAngle=0;
- m_dims = new DynamicDimensionDataCollection();
- Dimension dim1 = new AlignedDimension();
- dim1.SetDatabaseDefaults();
- m_dims.Add(new DynamicDimensionData(dim1,true,true));
- Dimension dim2 = new AlignedDimension();
- dim2.SetDatabaseDefaults();
- m_dims.Add(new DynamicDimensionData(dim2,true,true));
- }
-
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- JigPromptOptions jigOpts = new JigPromptOptions();
- jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted | UserInputControls.NoNegativeResponseAccepted);
-
- if(mPromptCounter == 0)
- {
- jigOpts.Message = "\nInput InsertPoint:";
- PromptPointResult dres = prompts.AcquirePoint(jigOpts);
-
- Point3d positionTemp = dres.Value;
- if(positionTemp != mPosition)
- {
- mPosition = positionTemp;
- }
- else
- return SamplerStatus.NoChange;
- if(dres.Status == PromptStatus.Cancel)
- return SamplerStatus.Cancel;
- else
- return SamplerStatus.OK;
-
-
- }
- else if (mPromptCounter == 1)
- {
- jigOpts.BasePoint = mPosition;
- jigOpts.UseBasePoint = true;
- jigOpts.Message = "\nInput Angle:";
- double angleTemp = -1;
- PromptPointResult res = prompts.AcquirePoint(jigOpts);
- mAnglePnt = res.Value;
- angleTemp = mAnglePnt.GetVectorTo(mPosition).AngleOnPlane(
- new Plane(
- Application.DocumentManager.MdiActiveDocument.Database.Ucsorg,
- Application.DocumentManager.MdiActiveDocument.Database.Ucsxdir,
- Application.DocumentManager.MdiActiveDocument.Database.Ucsydir
- ));
- if (angleTemp != mAngle)
- mAngle = angleTemp;
- else
- return SamplerStatus.NoChange;
- if(res.Status == PromptStatus.Cancel)
- return SamplerStatus.Cancel;
- else
- return SamplerStatus.OK;
-
- }
- else
- {
- return SamplerStatus.NoChange;
- }
-
-
- }
- protected override bool Update()
- {
-
- try
- {
- ((BlockReference)Entity).Position=mPosition;
- ((BlockReference)Entity).Rotation =mAngle;
- UpdateDimensions();
-
- }
- catch(System.Exception)
- {
- return false;
- }
-
- return true;
- }
- protected override DynamicDimensionDataCollection GetDynamicDimensionData(double dimScale)
- {
- return m_dims;
- }
- protected override void OnDimensionValueChanged(Autodesk.AutoCAD.DatabaseServices.DynamicDimensionChangedEventArgs e)
- {
-
- }
- void UpdateDimensions()
|