.NET

Reply
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 1 of 3 (118 Views)

Remember Input

118 Views, 2 Replies
05-31-2005 12:02 AM
I've tried to get a distance with following code.
When i do it the first time it should just ask for the distande.
The next time it should use the last distance as the default value.
But when i use the default value by entering enter, the next time it will use <0> as the default distance. But why?
What do i have to do to get allways the right distance as the default value.
I also want to remember the last input of the distance and the lenght in this drawing just for this session, like in acad. And i would like to remember it for each drawing.
I don't want the same distance for all drawings (like in command offset).
What would be the best way to do this? XRecords instead of Events? Maybe there is an example somewhere.

[code]#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

using System.Threading;
using System.Globalization;

#endregion

namespace RSNNAcadApp.Test
{
public class Test
{
static PromptDistanceOptions useThisDistanceOption;
static PromptDoubleResult useThisDistanceResult;
private double Dist;
private int Luprec = Application.DocumentManager.MdiActiveDocument.Database.Luprec;
public Test()
{
Database db = Application.DocumentManager.MdiActiveDocument.Database; //oder: entid.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptDistanceOptions opt1 = new PromptDistanceOptions("Abstand zeigen");

opt1.AllowNegative = false;
opt1.AllowZero = false;
opt1.AllowNone = false;
opt1.UseDashedLine = true;
PromptDoubleResult res = null;
if (useThisDistanceResult != null)
{
res = useThisDistanceResult;
Dist = res.Value;
string DistKeyword = Dist.ToString("F" + Luprec.ToString());
opt1.DefaultValue = Dist;
}
else
{

}

//USAGE OF INPUT CONTEXT REACTORS
ed.PromptingForDistance += new PromptDistanceOptionsEventHandler(handle_promptDistanceOptions);
ed.PromptedForDistance += new PromptDoubleResultEventHandler(handle_promptDistanceResult);

res = ed.GetDistance(opt1);

ed.PromptingForDistance -= new PromptDistanceOptionsEventHandler(handle_promptDistanceOptions);
ed.PromptedForDistance -= new PromptDoubleResultEventHandler(handle_promptDistanceResult);

if (res.Status == PromptStatus.OK)
{
Dist = res.Value;
ed.WriteMessage(String.Format("Abstand = {0}", Dist.ToString()));
}
else
{
return;
}

}

private static void handle_promptDistanceOptions(object sender, PromptDistanceOptionsEventArgs e)
{
useThisDistanceOption = e.Options;
}
private static void handle_promptDistanceResult(object sender, PromptDoubleResultEventArgs e)
{
useThisDistanceResult = e.Result;
}
}

}[/code]


Roland
*Albert Szilvasy
Message 2 of 3 (118 Views)

Re: Remember Input

05-31-2005 10:32 AM in reply to: RolandF
How about this?

#region Using directives

using System;
using System.Text;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

using System.Threading;
using System.Globalization;

#endregion

namespace RSNNAcadApp.Test
{
public class Test
{
private double m_dist; //last distance chosen (per-document)
private bool m_firstTime = true; //first invocation of "test"?
(per-document)

//use a non-static command method so the enclosing class (Test) will
be instantiated
//for each document
[CommandMethod("test")]
public void DoIt()
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
PromptDistanceOptions opt1 = new PromptDistanceOptions("Abstand
zeigen");

opt1.AllowNegative = false;
opt1.AllowZero = false;
opt1.AllowNone = false;
opt1.UseDashedLine = true;
if (!m_firstTime)
opt1.DefaultValue = m_dist;

PromptDoubleResult res = ed.GetDistance(opt1);

if (res.Status == PromptStatus.OK)
{
m_dist = res.Value;
ed.WriteMessage(String.Format("Abstand = {0}",
m_dist.ToString()));
}
m_firstTime = false;
}
}
}
wrote in message news:4860287@discussion.autodesk.com...
I've tried to get a distance with following code.
When i do it the first time it should just ask for the distande.
The next time it should use the last distance as the default value.
But when i use the default value by entering enter, the next time it will
use <0> as the default distance. But why?
What do i have to do to get allways the right distance as the default value.
I also want to remember the last input of the distance and the lenght in
this drawing just for this session, like in acad. And i would like to
remember it for each drawing.
I don't want the same distance for all drawings (like in command offset).
What would be the best way to do this? XRecords instead of Events? Maybe
there is an example somewhere.

[code]#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

using System.Threading;
using System.Globalization;

#endregion

namespace RSNNAcadApp.Test
{
public class Test
{
static PromptDistanceOptions useThisDistanceOption;
static PromptDoubleResult useThisDistanceResult;
private double Dist;
private int Luprec =
Application.DocumentManager.MdiActiveDocument.Database.Luprec;
public Test()
{
Database db =
Application.DocumentManager.MdiActiveDocument.Database; //oder:
entid.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
db.TransactionManager;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");

Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
PromptDistanceOptions opt1 = new PromptDistanceOptions("Abstand
zeigen");

opt1.AllowNegative = false;
opt1.AllowZero = false;
opt1.AllowNone = false;
opt1.UseDashedLine = true;
PromptDoubleResult res = null;
if (useThisDistanceResult != null)
{
res = useThisDistanceResult;
Dist = res.Value;
string DistKeyword = Dist.ToString("F" + Luprec.ToString());
opt1.DefaultValue = Dist;
}
else
{

}

//USAGE OF INPUT CONTEXT REACTORS
ed.PromptingForDistance += new
PromptDistanceOptionsEventHandler(handle_promptDistanceOptions);
ed.PromptedForDistance += new
PromptDoubleResultEventHandler(handle_promptDistanceResult);

res = ed.GetDistance(opt1);

ed.PromptingForDistance -= new
PromptDistanceOptionsEventHandler(handle_promptDistanceOptions);
ed.PromptedForDistance -= new
PromptDoubleResultEventHandler(handle_promptDistanceResult);

if (res.Status == PromptStatus.OK)
{
Dist = res.Value;
ed.WriteMessage(String.Format("Abstand = {0}",
Dist.ToString()));
}
else
{
return;
}

}

private static void handle_promptDistanceOptions(object sender,
PromptDistanceOptionsEventArgs e)
{
useThisDistanceOption = e.Options;
}
private static void handle_promptDistanceResult(object sender,
PromptDoubleResultEventArgs e)
{
useThisDistanceResult = e.Result;
}
}

}[/code]


Roland
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 3 of 3 (118 Views)

Re: Remember Input

05-31-2005 12:07 PM in reply to: RolandF
Thank you Albert,
i think that's what i wanted ;-)

Roland
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.