Message 1 of 7
Draw jig oject extend with section line extend draw oject
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Geometry;
using palet.Startup;
using System.Runtime.InteropServices;
using Exception = System.Exception;
using Autodesk.AutoCAD.ApplicationServices;
using System.Security.Cryptography;
using System.Globalization;
using Autodesk.AutoCAD.Interop.Common;
namespace palet.Jig
{
public class MyBlockJig_sec : DrawJig
{
public Point3d _point;
private ObjectId _blockId = ObjectId.Null;
private string str_Prompt = "";
private bool IsKeyword=false;
public static Point3d _basePoint;
public PromptResult DragMe(ObjectId i_blockId, out Point3d o_pnt, String Prompt, ref bool IsKeyword)
{
str_Prompt = Prompt;
_blockId = i_blockId;
var ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
var jigRes = ed.Drag(this);
//o_pnt = _point;
o_pnt = _basePoint;
return jigRes;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
var jigOpts = new JigPromptPointOptions("");
jigOpts.UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.NullResponseAccepted;
try
{
jigOpts.Message = str_Prompt; // "Select a point:";
if (str_Prompt.Contains("bubble"))
{
jigOpts.Keywords.Add("neXt");
jigOpts.Keywords.Add("Prev");
}
else if (str_Prompt.Contains("flip Vert"))
{
if (str_Prompt.Contains("TL/TC/TR/ML/MC/MR/BL/BC/BR")) //These are OT selection
{
jigOpts.Keywords.Add("Horiz");
jigOpts.Keywords.Add("Vert");
jigOpts.Keywords.Add("TL");
jigOpts.Keywords.Add("TC");
jigOpts.Keywords.Add("TR");
jigOpts.Keywords.Add("ML");
jigOpts.Keywords.Add("MC");
jigOpts.Keywords.Add("MR");
jigOpts.Keywords.Add("BL");
jigOpts.Keywords.Add("BC");
jigOpts.Keywords.Add("BR");
}
else
{
jigOpts.Keywords.Add("Vert");
jigOpts.Keywords.Add("Manual");
}
}
else if (str_Prompt.Contains("flip Horiz/ flip Vert / Auto"))
{
jigOpts.Keywords.Add("Horiz");
jigOpts.Keywords.Add("Vert");
}
else if (str_Prompt.Contains("Flip/Manual"))
{
jigOpts.Keywords.Add("Flip");
jigOpts.Keywords.Add("Manual");
}
else if (str_Prompt.Contains("Flip/Auto"))
{
jigOpts.Keywords.Add("Flip");
jigOpts.Keywords.Add("Auto");
}
else if (str_Prompt.Contains("TL / TC / TR / ML / MC / MR / BL / BC / BR"))
{
jigOpts.Keywords.Add("Horiz");
jigOpts.Keywords.Add("Vert");
jigOpts.Keywords.Add("TL");
jigOpts.Keywords.Add("TC");
jigOpts.Keywords.Add("TR");
jigOpts.Keywords.Add("ML");
jigOpts.Keywords.Add("MC");
jigOpts.Keywords.Add("MR");
jigOpts.Keywords.Add("BL");
jigOpts.Keywords.Add("BC");
jigOpts.Keywords.Add("BR");
}
else if (str_Prompt.Contains("Inspoint"))
{
jigOpts.Keywords.Add("Inspoint");
}
else if (str_Prompt.Contains("Rotate"))
{
jigOpts.Keywords.Add("Flip");
jigOpts.Keywords.Add("Rotate");
jigOpts.Keywords.Add("Auto gap off");
//jigOpts.Keywords.Add("Set default gap");
//jigOpts.Keywords.Add("reSet default gap");
}
else
{
jigOpts.Keywords.Add("Flip");
}
//jigOpts.Keywords.Add("No");
//jigOpts.AllowNone = false;
jigOpts.BasePoint = _basePoint;
jigOpts.UseBasePoint = true;
jigOpts.Cursor = CursorType.RubberBand;
/* jigOpts.UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.AnyBlankTerminatesInput
| UserInputControls.GovernedByOrthoMode | UserInputControls.GovernedByUCSDetect | UserInputControls.UseBasePointElevation
| UserInputControls.InitialBlankTerminatesInput | UserInputControls.NullResponseAccepted;*/
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
var jigRes = prompts.AcquirePoint(jigOpts);
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
var pt = jigRes.Value;
if (pt == _point)
return SamplerStatus.NoChange;
_point = pt;
if (jigRes.Status == PromptStatus.OK)
return SamplerStatus.OK;
return SamplerStatus.Cancel;
}
catch (Exception ex)
{
if (ex.Message.IndexOf("User input is a keyword", StringComparison.InvariantCultureIgnoreCase) != -1)
{
//' One of the keywords was entered
IsKeyword = true;
return SamplerStatus.Cancel;
}
else
{
return SamplerStatus.Cancel;
}
}
}
protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
{
var inMemoryBlockInsert = new BlockReference(_basePoint, _blockId);
inMemoryBlockInsert.TransformBy(Matrix3d.Scaling(mod_DC_Main.dbl_DC_ScaleFactor, _basePoint));
draw.Geometry.Draw(inMemoryBlockInsert);
inMemoryBlockInsert.Dispose();
return true;
}
public class mod_BlockJig_Sec
{
//public static Point3d _basePoint;
public static dynamic BlockJig_sec(string BL, String Prompt, double[] v_InsertionPoint, ref bool IsKeyword)
{
object Ret = null;
var ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
var db = ed.Document.Database;
var CadDocument = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
BlockReference ent = null;
try
{
using (var tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
BlockTableRecord blockTbRec = (BlockTableRecord)tr.GetObject(bt[BL], Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
var attInfos = new Dictionary<string, TextInfo>();
var blockJig = new MyBlockJig_sec();
//Point3d point;
Point3d point = new Point3d(v_InsertionPoint[0], v_InsertionPoint[1], v_InsertionPoint[2]);
_basePoint = point;
var res = blockJig.DragMe(blockTbRec.ObjectId, out point, Prompt, ref IsKeyword);//blockJig.DragMe(blockTbRec.ObjectId, out point, Prompt, ref IsKeyword);
Ret = res; // blockJig.DragMe(block.ObjectId, out point);
if (res.Status == PromptStatus.OK)
{
using (CadDocument.LockDocument())
{
BlockTableRecord curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite);
var insert = new BlockReference(point, blockTbRec.ObjectId);
insert.TransformBy(Matrix3d.Scaling(mod_DC_Main.dbl_DC_ScaleFactor, point));
curSpace.AppendEntity(insert);
tr.AddNewlyCreatedDBObject(insert, true);
// insert.ExplodeToOwnerSpace()
IsKeyword = true;
insert.Erase();
//Variables.StartPoint = point;
}
}
else
{
IsKeyword = true;
}
//mod__GetBlockReferenceByName.GetBlockReferenceByName(BL);
tr.Commit();
ed.Regen();
return Ret;
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.ToString());
return null;
}
}
struct TextInfo
{
public Point3d Position { get; private set; }
public Point3d Alignment { get; private set; }
public bool IsAligned { get; private set; }
public double Rotation { get; private set; }
public TextInfo(Point3d position, Point3d alignment, bool aligned, double rotation)
{
Position = position;
Alignment = alignment;
IsAligned = aligned;
Rotation = rotation;
}
}
private static Point3d GetAttributePosition(ObjectId id)
{
Point3d p = new Point3d();
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
// if the block rotation cosine is negative (i.e. 90° < br.Rotation < 270°)
if (Math.Cos(br.Rotation) > 0.0)
{
// search for "OUTSIDE_DISPLAY" attribute
foreach (ObjectId id1 in br.AttributeCollection)
{
AttributeReference attRef = (AttributeReference)tr.GetObject(id1, OpenMode.ForRead);
/*if (attRef.Tag == "OUTSIDE_DISPLAY")
{*/
// compute the displacement vector
double angle = attRef.Rotation - Math.PI * 0.5; // rotation - 90°
//double height = attRef.MTextAttribute.ActualHeight; // mtext total height
//Vector3d vector = new Vector3d(height * Math.Cos(angle), height * Math.Sin(angle), 0.0);
Vector3d vector = new Vector3d(Math.Cos(angle), Math.Sin(angle), 0.0);
attRef.Position = br.Position;
// move and rotate the attribute
attRef.UpgradeOpen();
// attRef.AlignmentPoint += vector;
attRef.Rotation += Math.PI;
p = attRef.Position;
// }
}
}
tr.Commit();
return p;
}
}
}
}
}
I am trying to perform the elow operation where I place the Oject then use drag oject to place the section attached is one expected and other what I am getting
Expected:
Issue When I runthe elow code.. I can inscert oject ut when I dreag it does not drag properly.. as in ist video