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

Remember Input

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
312 Views, 2 Replies

Remember Input

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
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

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
Message 3 of 3
Anonymous
in reply to: Anonymous

Thank you Albert,
i think that's what i wanted 😉

Roland

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