Author Topic: SendStringToExecute and GetPoint  (Read 7104 times)

0 Members and 1 Guest are viewing this topic.

tik

  • Guest
SendStringToExecute and GetPoint
« on: December 21, 2011, 11:09:40 AM »
I have a very simple command and all I doing on that is, Set the UCS  to World and get a point from the drawing. Problem I am having is, by running this command when I get prompted for pick pnt, I see in the message saying "Invalid Point" and also SendStringToExecute has no effect. I am attaching a image to show exactly what it is.

If I am just sending "_.ucs W " it seems to be working fine. If cant believe something this simple cause this much pain unless I am doing something wrong some where.

Thanks in advance

Tik.

[CommandMethod("SendCommandExample")]
        public void SendCommandExample()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            string strSend = "_.ucs W ";
            Application.DocumentManager.MdiActiveDocument.SendStringToExecute(strSend,true,false,true);           
            //Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
            Point3d pnt = new Point3d();
            PromptPointResult pPntResult;
            PromptPointOptions ptOpts = new PromptPointOptions("\nPick Pnt :");
            pPntResult =  Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(ptOpts);
            if (pPntResult.Status != PromptStatus.OK)
            {
               
            }
            pnt = pPntResult.Value;
        }

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: SendStringToExecute and GetPoint
« Reply #1 on: December 21, 2011, 11:38:09 AM »
Hi,
As far as you can, avoid using SendStringToExectute prior the end of a method  because it is asynchronous.

Instead of calling the _ucs command, you can try this:
Code: [Select]
ed.CurrentUserCoordinateSystem = Matrix3d.Identity;
Or, better I think, get your point in UCS coordinates with PromptPointResult and transform it with:
Code: [Select]
pPntResult.Value.TransformBy(ed.CurrentUserCoordinateSystem);
Speaking English as a French Frog

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: SendStringToExecute and GetPoint
« Reply #2 on: December 22, 2011, 07:35:10 AM »
Everytime someone uses SendStringToExecute God kills a puppy.  Just keep that in mind before trying to use it.
Revit 2019, AMEP 2019 64bit Win 10

tik

  • Guest
Re: SendStringToExecute and GetPoint
« Reply #3 on: December 22, 2011, 08:00:45 AM »
gile,

Thanks for the code.  I will give that a try.

MexicanCustard,

From your comments it looks like, using SendStringToExecute is not a good option at all.

Venting here .....
I am working on project converting a VBA project(from 2003) to .NET and all the estimates are based on line by line conversion from vba code to .net code but more and more I am converting, it is obvious that is not the case at all. I am running into issues of not finding equivalent .NET code.

kaefer

  • Guest
Re: SendStringToExecute and GetPoint
« Reply #4 on: December 22, 2011, 09:11:10 AM »
I am running into issues of not finding equivalent .NET code.

I'm not implying anything about portability of legacy VBA; I'm just looking at the object models of AutoCAD ActiveX and of ObjectARX Managed Wrapper. Much similarity, with two striking differences: The Database layer doesn't exist in ActiveX, at least not as intermediate level between Document and Resident Collections (SymbolTables etc.); and the ActiveX Drawing object hierarchy is flat, as opposed to inheritance from superclasses like Curve, Dimension etc., while encapsulating common traits.

Acknowledged that the Database level may make Document handling a little bit harder, but I can't imagine the object model as a major stumbling block. What about other, procedural aspects? Like, Transactions?

tik

  • Guest
Re: SendStringToExecute and GetPoint
« Reply #5 on: December 22, 2011, 09:42:45 AM »
Hi Kaefer,

My frustration is more with people in charge of the project who thought that it is going to be line to line coversion from vba to .net. In some cases when I take the old vba syntax and search in the API document I am not finding any thing and in those situations, I need to go with the assumption that what I am doing is right. Regarding the procedural things what did is , I created a ACAD wrapper which does all the work related to CAD and named most functions as close as the old VBA function names that way it is easy for me find the functions as I keep porting more code. My main concern is, any time rewriting a piece software can add bugs though it is porting code from language to other.

tik.

SGP2012

  • Guest
Re: SendStringToExecute and GetPoint
« Reply #6 on: December 22, 2011, 09:26:39 PM »
If you're porting from VBA to .NET, you might want to do the 'line by line' conversion using COM Interop. You can then use 'pure' .NET to extend the code later. That's by far the most efficient migration technique.

Check out the DevTV recordings and supporting material down at the bottom of this page - www.autodesk.com/vba. Slightly old now, but still relevant (i.e. you may have to use VS2008 to import your converted project - I think the converter was removed from VS2010).

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SendStringToExecute and GetPoint
« Reply #7 on: December 22, 2011, 09:45:49 PM »
Everytime someone uses SendStringToExecute God kills a puppy.  < ... >

I'm sure she doesn't ... but it was still a funny comment :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: SendStringToExecute and GetPoint
« Reply #8 on: December 22, 2011, 10:48:28 PM »
Everytime someone uses SendStringToExecute God kills a puppy.  Just keep that in mind before trying to use it.
:lmao: :lmao:
I would use it more if he would kill kittens instead.
 
All joking aside this is one example I thought SendStringToExecute might be helpful or is there a better way.
It comes from here and thanks to gile for the answer.
Some people at the office did not like to use MText, and when I needed to scale it using 'SCALETEXT', single line would end up overlapping each other like in the picture

 
Not to get into Annotative text, but setting the column width to 0 gives the same feel as creating multiple lines with single text, and to keep from setting the width to 0 and from picking each corner I used 'SendStringToExecute'.
 
Not the exact code I am using but basic idea
Code: [Select]
        [CommandMethod("MMC")]
        public void MMC()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptPointResult ppr = ed.GetPoint("\nSpecify insertion point: ");
           
            if (ppr.Status == PromptStatus.OK)
            {
                Point3d pt = ppr.Value;
                string cmd = string.Format("_mtext\n{0},{1},{2}\n_j\n_mc\n_w\n0\n", pt.X, pt.Y, pt.Z);
                doc.SendStringToExecute(cmd, false, false, true);
            }
        }
        [CommandMethod("MTL")]
        public void MTL()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptPointResult ppr = ed.GetPoint("\nSpecify insertion point: ");
            if (ppr.Status == PromptStatus.OK)
            {
                Point3d pt = ppr.Value;
                string cmd = string.Format("_mtext\n{0},{1},{2}\n_j\n_tl\n_w\n0\n", pt.X, pt.Y, pt.Z);
                doc.SendStringToExecute(cmd, false, false, true);
            }
        }
 

So in this situation can you think of a better way or use 'SendStringToExecute'?

Jeff H

  • Needs a day job
  • Posts: 6150
Re: SendStringToExecute and GetPoint
« Reply #9 on: January 18, 2012, 11:52:13 AM »
Sorry for killings some puppies after looking at this thread http://www.theswamp.org/index.php?topic=40688.0
looks like I found a better way.
Just trying it out and first shot to see if it worked
Code: [Select]
        public void MTX()
        {
            PromptPointResult ppr = Ed.GetPoint("\nSpecify insertion point: ");
            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }
            using (Transaction trx = Db.TransactionManager.StartTransaction())
            {
                using (MText mtxt = new MText())
                {
                    mtxt.Contents = "";
                    mtxt.Location = ppr.Value;
                    InplaceTextEditorSettings ipts = new InplaceTextEditorSettings();
                    mtxt.TextHeight = GetScaledTextHeight(Db.Cannoscale);
                                       
                    InplaceTextEditor.Invoke(mtxt, ipts);
                    if (!String.IsNullOrWhiteSpace(mtxt.Contents))
                    {
                        BlockTableRecord btr = (BlockTableRecord)trx.GetObject(Db.CurrentSpaceId, OpenMode.ForWrite, false);
                        btr.AppendEntity(mtxt);
                        trx.AddNewlyCreatedDBObject(mtxt, true);
                    }

                }
                trx.Commit();
            }
             
           
        }
 

***********************Edit****************************************
  Looks like InplaceTextEditorSettings came out in 2012
« Last Edit: January 23, 2012, 01:32:40 PM by Jeff H »

Irvin

  • Guest
Re: SendStringToExecute and GetPoint
« Reply #10 on: January 20, 2012, 05:10:46 AM »
Jeff,

Could you share the GetScaledTextHeight(Db.Cannoscale); method with me? :-)

Kind regards,

Irvin

Jeff H

  • Needs a day job
  • Posts: 6150
Re: SendStringToExecute and GetPoint
« Reply #11 on: January 21, 2012, 12:28:54 AM »
Hey Irvin,
 
That was something I had coded in for testing and was something like
Code: [Select]

  private double GetScaledTextHeight(AnnotationScale annoScale)
        {
            return (1.0 / annoScale.Scale) * StandardTextHeight;
        }

Where StandardTextHeight is 1/8", 3/32", etc......
but you probably can see problems that might arise using that logic.

Irvin

  • Guest
Re: SendStringToExecute and GetPoint
« Reply #12 on: January 23, 2012, 03:07:53 AM »
Hi Jeff,

Thanks for the code sample. Tought it might fix a problem im having.
The problem i have is with a an new annotative text. I need to manualy scale the text size.

In AutoCAD as i see it now i can enter text in modelspace (use Cannoscale variable) i can enter text in paperspace 1:1 and i can enter text while im in a viewport. How can i detect wheter i'm in paperspace or im in paper space in an active viewport. I need to get the different scale factors.

Could you or any one else help me with a solution for this problem?

Code: [Select]
        private double getscale(AnnotationScale scale)
        {
            Double Scale = 1;

            BlockTable blockTable = (BlockTable)AutoCAD.DocumentManager.MdiActiveDocument.TransactionManager.TopTransaction.GetObject(
                AutoCAD.DocumentManager.MdiActiveDocument.Database.BlockTableId, OpenMode.ForRead);
           
            BlockTableRecord currentSpace = (BlockTableRecord)AutoCAD.DocumentManager.MdiActiveDocument.TransactionManager.TopTransaction.GetObject(
                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.CurrentSpaceId, OpenMode.ForRead);

            if (currentSpace.ObjectId == blockTable[BlockTableRecord.ModelSpace])
            {
                 Scale = scale.DrawingUnits;
            }
            else(currentSpace.ObjectId == blockTable[BlockTableRecord.PaperSpace])
            {
                if (How to check if i'm in a vieport)
                {
                   How do i get the annotative scale from the viewport.
                   Scale = Viewport scale;
                 }
                 else
                 {
                    Scale = 1;
                 }
             }
             return Scale;
        }


Kind regard,

Irvin

« Last Edit: January 23, 2012, 04:07:31 AM by Irvin »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: SendStringToExecute and GetPoint
« Reply #13 on: January 23, 2012, 03:43:54 AM »
Hi,

Look at the TILMODE sysvar (or Database.Tilemode property) and the CVPORT sysvar.
Speaking English as a French Frog

Irvin

  • Guest
Re: SendStringToExecute and GetPoint
« Reply #14 on: January 23, 2012, 04:25:32 AM »
Gile,

Thanks for the rely. Looking at the tilemode it always gives me back 1.
Looking at the cvport gives me back 1 while im in paper space. When i enter a viewport it gives me a differtent number.

How can i get the viewport properies by that number so i can get the annotative scale from that object.

Kind regards,

Irvin