Author Topic: Can I make it any tougher?  (Read 4836 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Can I make it any tougher?
« on: December 08, 2006, 07:13:47 PM »
I guess I have a complete mental block on this C# language. Try as I might, I cannot get this to work. Everything goes fine until I want to output what I'm doing to the command line......at which point I get a major error thrown in Acad. I'll try to capture a PNG of the error in a few minutes.
Code: [Select]
            PromptDistanceOptions distPrmt = new PromptDistanceOptions("");
            distPrmt.Message = "\nOffset distance, negative for left side: ";
            distPrmt.DefaultValue = 5.0;
            PromptDoubleResult offDist = ed.GetDistance(distPrmt);
            ed.WriteMessage(offDist.Value.ToString());
In Debug mode I can see the offDist variable get set to {{OK}, 15.0} and I can inspect it and see that the value is 15.0. But once it gets to the WriteMessage line, Kaboom. Anyone (everyone) care to tell me what the heck I'm missing?  :|

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can I make it any tougher?
« Reply #1 on: December 08, 2006, 07:22:14 PM »
Jeff ,
How is ed defined ?

What is the exception ?

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_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Can I make it any tougher?
« Reply #2 on: December 08, 2006, 07:26:22 PM »
Jeez, now it works.....I guess I didn't rebuild it after changing this line:
ed.WriteMessage(offDist.Value.ToString());

from this:
ed.WriteMessage(offDist.Value.ToString("D"));

So now my question is this, how do I format the Value to output like this: 15.00' ? As it is now, it prints just 15 to the command line.

Kerry,

            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

The exception is:

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Can I make it any tougher?
« Reply #3 on: December 08, 2006, 07:33:01 PM »
just try sending it to writeline as offsetdist.value (not ToString()) and write line should be able to format it appropriately (I think from memory)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Can I make it any tougher?
« Reply #4 on: December 08, 2006, 07:33:22 PM »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can I make it any tougher?
« Reply #5 on: December 08, 2006, 07:35:25 PM »


Having fun ?


Quote
In Debug mode I can see the offDist variable get set to {{OK}, 15.0} ... 

good to see you got the debugger working in Express !
« Last Edit: December 08, 2006, 07:37:12 PM by Kerry Brown »
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can I make it any tougher?
« Reply #6 on: December 08, 2006, 07:45:04 PM »
Jeff, I'll have a look at the ToString Override for you ..
Autodesk.AutoCAD.EditorInput.PromptResult.ToString(IFormatProvider) : String

I think that should work ...
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can I make it any tougher?
« Reply #7 on: December 08, 2006, 07:49:55 PM »
Just an aside,
I've found this really handy
 - .NET Reflector, Version 4.2.50.0
http://www.aisto.com/roeder/dotnet/

Just load up :-
C:\ACAD2007\acmgd.dll
C:\ACAD2007\acdbmgd.dll
C:\ACAD2007\acmgdinternal.dll
%SystemRoot%\Microsoft.net\Framework\vxxxxx\System.Windows.Forms.dll
%SystemRoot%\Microsoft.net\Framework\vxxxxx\mscorlib.dll

Great for rainy weekends :-)





« Last Edit: December 09, 2006, 02:28:42 AM by Kerry Brown »
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_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Can I make it any tougher?
« Reply #8 on: December 08, 2006, 08:10:58 PM »
OK....
Mick, yes I tried that and it still only outputs what it wants. In this case it should be 15.00 but I only get 15 at the prompt.

Kerry, I've got lots of reading now, thanks. :-)

Tim, thanks for the link. Based on the discussion there I was able to get "N2" to work. "D2" throws the exception, but the Help says that d,D,n,N are all valid Format identifiers.......

Here's a quickie test that shows these in action:

Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace SelectFeature
{
    public class Class1
    {
        public Class1()
        {
        }
        [CommandMethod("TestMe1")]
        static public void testmenow()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            PromptDistanceOptions distPrmt = new PromptDistanceOptions("");
            distPrmt.Message = "\nOffset distance, negative for left side: ";
            distPrmt.DefaultValue = 5.0;
            PromptDoubleResult offDist = ed.GetDistance(distPrmt);
            ed.WriteMessage("Test1 Offset selected is: " + offDist.Value);
        }
        [CommandMethod("TestMe2")]
        static public void testmenow()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            PromptDistanceOptions distPrmt = new PromptDistanceOptions("");
            distPrmt.Message = "\nOffset distance, negative for left side: ";
            distPrmt.DefaultValue = 5.0;
            PromptDoubleResult offDist = ed.GetDistance(distPrmt);
            ed.WriteMessage("Test2 Offset selected is: " + offDist.Value.ToString("N2"));
        }
        [CommandMethod("TestMe3")]
        static public void testmenow()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            PromptDistanceOptions distPrmt = new PromptDistanceOptions("");
            distPrmt.Message = "\nOffset distance, negative for left side: ";
            distPrmt.DefaultValue = 5.0;
            PromptDoubleResult offDist = ed.GetDistance(distPrmt);
            ed.WriteMessage("Test3 Offset selected is: " + offDist.Value.ToString("D2"));
        }
     }
  }
This will create 3 commands, TestMe1, TestMe2 & TestMe3. 1 & 2 will work, but 3 should throw that exception.

I'm off to take some aspirin. This little problem has kicked my behind for 2 hours now......

BTW, Kerry, how'd you know we were going to be rained on all weekend?

LE

  • Guest
Re: Can I make it any tougher?
« Reply #9 on: December 08, 2006, 09:05:22 PM »
Two hours?..... it is nothing....  :-P

See if the code below helps.... you can change the format inside of the ToString("0.00") to change the precision, but do not if that is what you are looking for, I remember reading a comment by Tony Tanzillo about this issue, in the adesk net.... but do not have the link.

Code: [Select]
        [CommandMethod("TestMe3")]
        static public void testmenow()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            PromptDistanceOptions distPrmt = new PromptDistanceOptions("");
            distPrmt.Message = "\nOffset distance, negative for left side: ";
            distPrmt.DefaultValue = 5.0;
            PromptDoubleResult offDist = ed.GetDistance(distPrmt);
            if (offDist.Status != PromptStatus.OK) return;

            ed.WriteMessage("Test3 Offset selected is:  " + offDist.Value.ToString("00.00"));
        }

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can I make it any tougher?
« Reply #10 on: December 08, 2006, 09:17:38 PM »
Quote
BTW, Kerry, how'd you know we were going to be rained on all weekend?

heheheheh
one of my lesser talents :lol:


There MUST be a method in the NET API to format inits .. distance or somesuch .. I'll have a look this afternoon if no-one sorts it out ..

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.

LE

  • Guest
Re: Can I make it any tougher?
« Reply #11 on: December 08, 2006, 09:41:42 PM »
No samples out there.... now base on what Tony Tanzillo recommended, I went into the VS2005 IDE and click into the Class View icon, and on the View Class Diagram for the Autodesk.AutoCAD.Runtime

And we can use something like this:

Code: [Select]
string output = Converter.DistanceToString(offDist.Value, DistanceUnitFormat.Decimal, 2);
ed.WriteMessage("Test3 Offset selected is:  " + output);

r&r
« Last Edit: December 08, 2006, 11:08:55 PM by LE »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can I make it any tougher?
« Reply #12 on: December 08, 2006, 10:35:36 PM »
Nice investigation Luis !
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.

LE

  • Guest
Re: Can I make it any tougher?
« Reply #13 on: December 08, 2006, 11:11:44 PM »
Nice investigation Luis !



Yes... I'm trying to put good use of all the free time I have now... :)