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

Revision cloud

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
JonathanSommer2580
2541 Views, 8 Replies

Revision cloud

I have been searching hi and low for a means of using the .net API for inserting a revision cloud. More specifically using a jig to insert a revision cloud. Can anybody here point me in the right direction? Thanks.
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: JonathanSommer2580

I too am interested in this.  But a lack of response for the past few months doesn't bode well...

Message 3 of 9
Anonymous
in reply to: Anonymous

Not sure I have not messed with it but the revision cloud is nothing but a polyline. It uses that last used arc length stored in the registeriy but I did see any system variables given for that. 

So maybe you start thinking of creating a polyline with arcs

 

 

 

 

Message 4 of 9
Anonymous
in reply to: Anonymous

Got a reply from Dev Help on this subject and they said the same thing.

 

Here is some sample code for anyone else who needs it:

 

[CommandMethod("addPline")]

public static void addPline()

{

    Document doc = Application.DocumentManager.MdiActiveDocument;

    Database db = doc.Database;

    Editor ed = doc.Editor;

 

    using (Transaction Tx = db.TransactionManager.StartTransaction())

    {

        BlockTable table = Tx.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

        BlockTableRecord model = Tx.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

 

        Polyline polyline = new Polyline();

 

        polyline.SetDatabaseDefaults();

 

        double angleDeg = 180.0;

 

        //Converts angle to radians and then compute bulge. (Nb. Atan(1) = Pi/4)

        double bulge = Math.Tan(angleDeg * Math.Atan(1) / 180.0);

 

        polyline.AddVertexAt(polyline.NumberOfVertices, new Point2d(0, 0), bulge, 0, 0);

        polyline.AddVertexAt(polyline.NumberOfVertices, new Point2d(10, 10), -bulge, 0, 0);

        polyline.AddVertexAt(polyline.NumberOfVertices, new Point2d(20, 20), bulge, 0, 0);

        polyline.AddVertexAt(polyline.NumberOfVertices, new Point2d(30, 30), -bulge, 0, 0);

 

        model.AppendEntity(polyline);

        Tx.AddNewlyCreatedDBObject(polyline, true);

 

        Tx.Commit();

    }

}

Message 5 of 9
LE3
Advocate
in reply to: JonathanSommer2580

Hi Chris,

 

Wow that's what they provide... hmmm

 

Anyway, here is a modified version of a jig sample provided by Kean W. in his web site http://through-the-interface.typepad.com

 

Notes:

- it does not closed automatically (just press enter to stop and do that when getting closer to the starting point, the arcs are drawn based on the point selection)

 

 

See if helps, have fun!

 

#region Revision Cloud - Simple

class RevCloudJig : EntityJig

{

// Use a separate variable for the most recent point...

// Again, not strictly necessary, but easier to reference

Point3d m_tempPoint;

Plane m_plane;

bool m_isArcSeg = false;

bool m_isUndoing = false;

// At this stage, our arc segments will

// have a fixed bulge of 1.0...

// Later we may update the routine to determine

// the bulge based on the relative location

// of the cursor

const double kBulge = 1.0;

public RevCloudJig(Matrix3d ucs) : base(new Polyline())

{

// Create a temporary plane, to help with calcs

Point3d origin = new Point3d(0, 0, 0);

Vector3d normal = new Vector3d(0, 0, 1);

normal = normal.TransformBy(ucs);

m_plane = new Plane(origin, normal);

// Create polyline, set defaults, add dummy vertex

Polyline pline = Entity as Polyline;

pline.SetDatabaseDefaults();

pline.Normal = normal;

AddDummyVertex();

}

protected override SamplerStatus Sampler(JigPrompts prompts)

{

JigPromptPointOptions jigOpts = new JigPromptPointOptions();

jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates |

UserInputControls.NullResponseAccepted | UserInputControls.NoNegativeResponseAccepted);

 

m_isUndoing = false;

m_isArcSeg = true;

Polyline pline = Entity as Polyline;

if (pline.NumberOfVertices == 1)

{

// For the first vertex, just ask for the point

jigOpts.Message = "\nStart point of revision: ";

}

else if (pline.NumberOfVertices > 1)

{

jigOpts.SetMessageAndKeywords("\nSpecify next point or [Undo]: ", "Undo");

// For subsequent vertices, use a base point

//if (m_isArcSeg)

//{

// jigOpts.SetMessageAndKeywords("\nSpecify endpoint of arc or [Line/Undo]: ", "Line Undo");

//}

//else

//{

//jigOpts.SetMessageAndKeywords("\nSpecify next point or [Arc/Undo]: ", "Arc Undo");

//}

}

else // should never happen

return SamplerStatus.Cancel;

// Get the point itself

PromptPointResult res = prompts.AcquirePoint(jigOpts);

if (res.Status == PromptStatus.Keyword)

{

if (res.StringResult == "Arc")

{

m_isArcSeg = true;

}

//else if (res.StringResult == "Line")

//{

// m_isArcSeg = false;

//}

else if (res.StringResult == "Undo")

{

m_isUndoing = true;

}

return SamplerStatus.OK;

}

else if (res.Status == PromptStatus.OK)

{

// Check if it has changed or not

// (reduces flicker)

if (m_tempPoint == res.Value)

{

return SamplerStatus.NoChange;

}

else

{

m_tempPoint = res.Value;

return SamplerStatus.OK;

}

}

return SamplerStatus.Cancel;

}

protected override bool Update()

{

// Update the dummy vertex to be our

// 3D point projected onto our plane

Polyline pline = Entity as Polyline;

pline.SetPointAt(pline.NumberOfVertices - 1, m_tempPoint.Convert2d(m_plane));

// If it's supposed to be an arc segment,

// set the bulge appropriately

if (m_isArcSeg)

{

pline.SetBulgeAt(pline.NumberOfVertices - 1, kBulge);

}

//else // Otherwise, it's a line, so set the bulge to zero

//{

// pline.SetBulgeAt(pline.NumberOfVertices - 1, 0);

//}

return true;

}

public Entity GetEntity()

{

return Entity;

}

public bool IsArcSegment()

{

return m_isArcSeg;

}

public bool IsUndoing()

{

return m_isUndoing;

}

public void AddDummyVertex()

{

// Create a new dummy vertex...

// can have any initial value

Polyline pline = Entity as Polyline;

pline.AddVertexAt(pline.NumberOfVertices, new Point2d(0, 0), 0, 0, 0);

}

public void RemoveDummyVertex()

{

Polyline pline = Entity as Polyline;

// Let's first remove our dummy vertex

if (pline.NumberOfVertices > 0)

{

pline.RemoveVertexAt(pline.NumberOfVertices - 1);

}

// And then check the type of the last segment

if (pline.NumberOfVertices >= 2)

{

double blg = pline.GetBulgeAt(pline.NumberOfVertices - 2);

m_isArcSeg = (blg != 0);

}

}

public void AdjustSegmentType(bool isArc)

{

// Change the bulge of the previous segment,

// if necessary

double bulge = 0.0;

if (isArc)

bulge = kBulge;

Polyline pline = Entity as Polyline;

if (pline.NumberOfVertices >= 2)

pline.SetBulgeAt(pline.NumberOfVertices - 2, bulge);

}

}

[CommandMethod("MYREVCLOUD")]

public void cmd_revcloudJig()

{

Document doc = Application.DocumentManager.MdiActiveDocument;

Editor ed = doc.Editor;

// Get the current UCS, to pass to the Jig

Matrix3d ucs = ed.CurrentUserCoordinateSystem;

// Create our Jig object

RevCloudJig jig = new RevCloudJig(ucs);

// Loop to set the vertices directly on the polyline

bool bPoint = false;

bool bKeyword = false;

bool bComplete = false;

do

{

PromptResult res = ed.Drag(jig);

bPoint = (res.Status == PromptStatus.OK);

// A new point was added

if (bPoint) jig.AddDummyVertex();

bKeyword = (res.Status == PromptStatus.Keyword);

if (bKeyword)

{

if (jig.IsUndoing())

{

jig.RemoveDummyVertex();

}

else

{

jig.AdjustSegmentType(jig.IsArcSegment());

}

}

// Null input terminates the command

bComplete = (res.Status == PromptStatus.None);

if (bComplete)

// Let's clean-up the polyline before adding it

jig.RemoveDummyVertex();

} while ((bPoint || bKeyword) && !bComplete);

// If the jig completed successfully,

// add the polyline

if (bComplete)

{

Polyline pline = jig.GetEntity() as Polyline;

if (pline.NumberOfVertices > 1)

{

// Append entity

Database db = doc.Database;

Transaction tr = db.TransactionManager.StartTransaction();

using (tr)

{

BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);

BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

btr.AppendEntity(pline);

tr.AddNewlyCreatedDBObject(pline, true);

tr.Commit();

}

}

}

}

#endregion

Message 6 of 9
Anonymous
in reply to: LE3

Hi Luis!

 

Yes, that is all they returned in their reply...  Not an unusual reply for Dev Help.  I'll try your code.  You always give out good help.

Message 7 of 9
JonathanSommer2580
in reply to: Anonymous

HI all thanks for the responses!  I had completely abandoned this thread until I randomly came back upon it.  Luis I did try doing some code very similar to your response based on the same Kean blog post.  My code had the same issues though.  You still have to click the mouse to add each Vertex point which of course in a regular revision cloud you don't, plus flickering starts as your polyline starts to have several vertexes and the jig has to redraw the entire polyline. 

 

Of course some method of determining mouse coordinate from last vertex and adding a vertex to the polyline without user clicking would be nessessary.  Also as mentioned before the regular AutoCAD revision cloud appears to "commit" the polyline up to the last vertex, and when a new vertex is entered it probably updates or replaces the polyline with the added vertex.  This way you don't have the massive flickering as the jig doesn't have to redraw the entire polyline. 

 

Anyone know how to get user mouse coordinates without the user clicking in a jig?  That would really help and I could try things from there.  It would really be awesome if Kean did a blog post on this subject.  How does one send him request for such things? 

Message 8 of 9
LE3
Advocate
in reply to: JonathanSommer2580

Got the chance to port the autolisp code, idea and concept by David Harrington to C# - Did just the basic, does not include all (change the arc length or save the value for next use), but the command works as in the early days.

 

Anyone can add any missing features, attached it is the full source code file.

 

Provided as-is.

 

HTH.

 

Sample:

//
// Based on the original Code, idea and concept by David Harrington
//
// Code ported to C# by LE OCT.24.2010.
//

namespace RevCloudNET
{
    public class RevCloudCommand
    {
        // ARX: int acedGrRead(int track, int * type, struct resbuf * result);
        [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int acedGrRead(int track, out int display, IntPtr result);
      
        // ARX: int acedCmd(const struct resbuf * rbp);
        [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
        extern static int acedCmd(IntPtr rbp);

        const int RTNORM = 5100;
        const int RTCAN = -5002;
        const short RTSTR = 5005;
        const int RT3DPOINT = 5009;
        const int RTREAL = 5001;

        public static void drawCloud()
        {
            if (AcadApp.DocumentManager.IsApplicationContext) return;

            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            int status = 0;
            double incAngle = 110.0;
            double arcDist = 0.0;

            if (Convert.ToInt32(AcadApp.GetSystemVariable("DIMSCALE")) == 0)
                arcDist = 0.375;
            else
                arcDist = 0.375 * Convert.ToInt32(AcadApp.GetSystemVariable("DIMSCALE"));

            PromptPointResult res = ed.GetPoint("\nPick cloud start point: ");
            if (res.Status != PromptStatus.OK) return;

 

...

Message 9 of 9
JonathanSommer2580
in reply to: LE3

Thanks Luis for the code!  Part of the revision cloud routine I am trying to do is once a revision cloud is finished the user then inserts a block reference.  I found that if the user cancels the revision cloud the code still wants 2 more escape presses before it completely exits out of the Revision cloud.  Unfortunatly when the user tries to insert the block reference Autocad then throws an unhandled exception. I tried several things to try and not get the this to happen, Nothing has been successful so far.  I'll post if I come up with anything.  I really wish Kean would do this in his blog. 

 

I've got a temporary solution and that is to have the user insert the block reference first then do the cloud.  Of course that is the solution I had before but that is not what everyone is used  to in the old lisp routine we had and they already pitched a fit about that.  Some people just despise change. 

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