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

Jig

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
quigs
1774 Views, 10 Replies

Jig

Hi there,
I have made my own jig based on Jerry Winters Jig example:
http://au.autodesk.com/ama/images/media/CP301-1L---Handson-introduction-to-the-art-of-making-AutoCAD-jigs.pdf

After the jig has ean, how do you then turn those pretty jigged lines into actually lines in your drawing.

Cheers,

Martin Quigley.
My name is Martin.. 😄
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: quigs

If you're not familiar with adding objects to a drawing, then you're
probably getting ahead of yourself with Jigs.

Try studying the basics (which include adding entities to a drawing) before
you getting into jigs. Download the API samples and labs and go through
them, because they show how to do what you ask.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6277368@discussion.autodesk.com...
Hi there,
I have made my own jig based on Jerry Winters Jig example:
http://au.autodesk.com/ama/images/media/CP301-1L---Handson-introduction-to-the-art-of-making-AutoCAD-jigs.pdf

After the jig has ean, how do you then turn those pretty jigged lines into
actually lines in your drawing.

Cheers,

Martin Quigley.
Message 3 of 11
quigs
in reply to: quigs

Hi Tony.
Allow me to iterate on my situation:

I have created a command called slope that inserts
a fall line after specifying 2 points, then draws the horizontal
& vertical connecting lines to make a right triangle, and
inserts the slope grade as text.

Next I created a jig (separately), but when I came to
sticking them together I had problems.

The main thing I can’t do is use the jigs variables
to draw the geometry as the jig only tracks the first
point and returns the last variables value.

Cheers,

Martin.
My name is Martin.. 😄
Message 4 of 11
_gile
in reply to: quigs

Hi,

Here's a little sample.
It seems to work, but I'm a newby too.

{code}using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace SlopeJigSample
{
public class SlopeCommand
{
class SlopeJig : EntityJig
{
Polyline m_pline;
Point3d m_dragPt;
Point3d m_fixPt;

public SlopeJig(Polyline pline, Point3d dragPt, Point3d fixPt)
: base(pline)
{
m_dragPt = dragPt;
m_fixPt = fixPt;
m_pline = pline;
}
protected override bool Update()
{
Point2d pt1 = new Point2d(m_dragPt.X, m_fixPt.Y);
Point2d pt2 = new Point2d(m_dragPt.X, m_dragPt.Y);
m_pline.SetPointAt(1, pt1);
m_pline.SetPointAt(2, pt2);
return true;
}

protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jppo = new JigPromptPointOptions("\nSpecify second point: ");
jppo.UserInputControls = (UserInputControls.Accept3dCoordinates);
PromptPointResult ppr = prompts.AcquirePoint(jppo);
if (ppr.Status == PromptStatus.OK)
{
if (ppr.Value.IsEqualTo(m_dragPt))
return SamplerStatus.NoChange;
else
{
m_dragPt = ppr.Value;
return SamplerStatus.OK;
}
}
return SamplerStatus.Cancel;
}
}

[CommandMethod("SLOPE")]
public void test()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointResult ppr = ed.GetPoint("\nSpecify first point: ");
if (ppr.Status == PromptStatus.OK)
{
Matrix3d UCS = ed.CurrentUserCoordinateSystem;
Point3d fixPt = ppr.Value.TransformBy(UCS);
Point2d pt = new Point2d(fixPt.X, fixPt.Y);
Polyline pline = new Polyline(3);
pline.Closed = true;
pline.AddVertexAt(0, pt, 0.0, 0.0, 0.0);
pline.AddVertexAt(0, pt, 0.0, 0.0, 0.0);
pline.AddVertexAt(0, pt, 0.0, 0.0, 0.0);

SlopeJig jig = new SlopeJig(pline, fixPt, fixPt);
PromptResult res = ed.Drag(jig);
if (res.Status == PromptStatus.OK)
{
Point3d p0 = pline.GetPoint3dAt(0);
Point3d p1 = pline.GetPoint3dAt(1);
Point3d p2 = pline.GetPoint3dAt(2);
double slope = Math.Abs((p2.Y - p0.Y) / (p2.X - p0.X));
Line hLine = new Line(p0, p1);
Line vLine = new Line(p1, p2);
Line sLine = new Line(p0, p2);
DBText txt = new DBText();
txt.Position = p0;
txt.HorizontalMode = TextHorizontalMode.TextCenter;
txt.VerticalMode = TextVerticalMode.TextBottom;
txt.AlignmentPoint = p0 + (p2 - p0).DivideBy(2.0);
txt.TextString = String.Format("{0:p}", slope);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(hLine);
tr.AddNewlyCreatedDBObject(hLine, true);
btr.AppendEntity(vLine);
tr.AddNewlyCreatedDBObject(vLine, true);
btr.AppendEntity(sLine);
tr.AddNewlyCreatedDBObject(sLine, true);
btr.AppendEntity(txt);
tr.AddNewlyCreatedDBObject(txt, true);
tr.Commit();
}
}
else
pline.Dispose();
}
}
}
}{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 11
quigs
in reply to: quigs

Hi _gile,
thank you so much for an amazing response. How ever, I am using VB.NET.
BUT!!! I'm sure I can pick through and see if there is anything I can use.

Thanks again.

Martin. Edited by: quigs on Oct 26, 2009 1:11 PM
My name is Martin.. 😄
Message 6 of 11
_gile
in reply to: quigs

Glad it helps.
They're many code converters on the web (Google for "Convert C# VB).
Maybe wait for a "master" (as Tony T) sees the code to say if every thing's correct ('Im not sure I have to dispose the pline if the user cancels).


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 11
Anonymous
in reply to: quigs

{quote}

The main thing I can't do is use the jigs variables
to draw the geometry as the jig only tracks the first
point and returns the last variables value.

{quote}

In that case, you probably should consider even more basic,
non AutoCAD-specific learning.

No, the jig isn't going to track the data input for you, so you
have to write the code that does that.

You can store data in various types of .NET classes like the
List, ArrayList, Point3dCollection, etc., for later use.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6277676@discussion.autodesk.com...
Hi Tony.
Allow me to iterate on my situation:

I have created a command called slope that inserts
a fall line after specifying 2 points, then draws the horizontal
& vertical connecting lines to make a right triangle, and
inserts the slope grade as text.

Next I created a jig (separately), but when I came to
sticking them together I had problems.

The main thing I can't do is use the jigs variables
to draw the geometry as the jig only tracks the first
point and returns the last variables value.

Cheers,

Martin.
Message 8 of 11
Anonymous
in reply to: quigs

I didn't have time to look too closely at your code, but in general, if a
new DBObject isnt added to a database, you have to dispose it.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

<_gile> wrote in message news:6277842@discussion.autodesk.com...
Glad it helps.
They're many code converters on the web (Google for "Convert C# VB).
Maybe wait for a "master" (as Tony T) sees the code to say if every thing's
correct ('Im not sure I have to dispose the pline if the user cancels).
Message 9 of 11
_gile
in reply to: quigs

Thanks Tony.

I'd be quite right if I didn't forget to remove the last "else" when I changed the code to add lines to the ModelSpace instead of the polyline.

Attached a corrected code.


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 10 of 11
Anonymous
in reply to: quigs

It would be better to put the Polyline under control
of a using(...), because it won't get disposed if an
exception is thrown before the call to Dispose() is
reached.

The same holds true for the other objects you're
adding to the database. If an exception is thrown
before the call to Append() that adds the entity to
the block, the entity will not be deterministically
disposed. The entity will still be disposed of by the
garbage collector, but because that happens in a
non-AutoCAD thread, it can crash AutoCAD.

The easiest way to deal with that, is to put all of
the objects that must be disposed of in a List as
they're created, and in the finally{} of a try/finally,
call Dispose() on every item in the list. That works
because even if the objects do become database-
resident, calling Dispose() on them does no harm,
and is essentially a 'no-op'.

Here are bare-bones versions of a few classes I
routinely use to deal with situations like that:

http://www.caddzone.com/EntityList.cs


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

<_gile> wrote in message news:6278441@discussion.autodesk.com...
Thanks Tony.

I'd be quite right if I didn't forget to remove the last "else" when I
changed the code to add lines to the ModelSpace instead of the polyline.

Attached a corrected code.
Message 11 of 11
_gile
in reply to: quigs

Thank you very much Tony.


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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