|
Hello
Well, I wonder a bit about how your code did compile at all!!
your main method is public while it should have been static private. This -I believe- should make a compile error!!
Anyway, I don't understand much of Autocad's interop method calls. I hope you are sure they should do the work. You said that the elapsed event is fired?? Does that mean that your CancelCommand is called and exctuted properly?
BTW:
You've declared DwgList twice. The one in main method is not the one you are accessing in the CancelCommand method. Try to debug through your code and see its value in the first time the event is fired.
Regards
|
|
|
|
|
I don't know why/how it compiles either, but it does. =D
The CancelCommand does fire, but you are correct in that my DwgList isn't anything in the CancelCommand part. I thought by adding it to the main part of the class, that it could be used inside the code, and shared with other parts of code as long as it was within the same class. Guess I was wrong, back to reading some more.
I guess I need to figure out how to have two global variable. One for DwgList and one for cnt . Or figure out a way to pass them between the calls to CommandCancel .
Thanks for your help, I don't think I would have ever got this far without it.
Tim
|
|
|
|
|
Hello
Well, forgive me if I say that your code sin't Object oriented. It looks like you have good experience in languages before C++. Your style is very procedural and it sin't that bad. It's just that your applications doesn't even have an interface?!! All you do is that you show a dialog, ake an input then do some interop. Well, either you make a full functional windows application or wrap your code in a dll or something. I didn't mean to ofend you - sincerely-, I just wanted to be as honest as I can with you.
Anyway, I wouldn't like to disrupt your code structure, so, the closest solution to get your code to work -though it would be better to remodel your code later to be more OO-, is simply to declare your variables as static thus you'd be able to call them by the class.
Here is your code, modified:
namespace Test
{
public class TimeLimitOpenv02
{
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedPostCommand@@YAHPBD@Z")]
extern static public int acedPostCommand(string cmd);
private static string[] DwgList;
public Document NewDoc;
DocumentCollection DocMan = AcadApp.DocumentManager;
System.Timers.Timer CountDownTimer;
private static int cnt = 1;
public TimeLimitOpenv02()
{
CountDownTimer = new System.Timers.Timer();
CountDownTimer.Elapsed += new ElapsedEventHandler(CancelCommand);
CountDownTimer.Interval = 10000;
}
~TimeLimitOpenv02()
{
CountDownTimer.Elapsed -= new ElapsedEventHandler(CancelCommand);
}
public void CancelCommand(object sender, ElapsedEventArgs e)
{
acedPostCommand ("CancelCmd");
NewDoc = DocMan.MdiActiveDocument;
NewDoc.CloseAndDiscard();
NewDoc = DocMan.Open (DwgList[cnt], true);
if (NewDoc != DocMan.MdiActiveDocument) {
DocMan.MdiActiveDocument = NewDoc;
}
++TimeLimitOpenv02.cnt;
if (TimeLimitOpenv02.cnt > TimeLimitOpenv02.DwgList.Length) {
CountDownTimer.Enabled = false;
CountDownTimer.Dispose();
}
NewDoc.SendStringToExecute ("_.3dorbit", false, false, true);
}
[CommandMethod("TestTimer", CommandFlags.Session)]
public void Main()
{
Autodesk.AutoCAD.Windows.OpenFileDialog Dia =
new Autodesk.AutoCAD.Windows.OpenFileDialog(
"Select drawings to update Cloud layer", "", "dwg", "",
Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
Dia.ShowDialog();
TimeLimitOpenv02.DwgList = Dia.GetFilenames();
if (DwgList.Length > 1)
{
CountDownTimer.Enabled = true;
Document NewDoc = DocMan.Open (DwgList[0], true);
if (NewDoc != DocMan.MdiActiveDocument) {
DocMan.MdiActiveDocument = NewDoc;
}
NewDoc.SendStringToExecute ("_.3dorbit\n", false, false, true);
}
}
}
}
BTW:
You still can access DwgList from your main , and your CancelCommand if you didn't redeclare it. Your redeclaration made a second local variable with the same name that masked the original one -I hope I'm making sense!;P-. Anyway, even though I totally don't like this static workaround, but it would relieve the ambiguity, and get your code to work. But if you want to make a windows application, at least it should have a form, shouldn't it? Well, Maybe you are making a command line tool -never liked them though-. Good luck! I hope it works this time.
Regards
|
|
|
|
|
Thanks for you help, and you can be as blunt as you want to be. I know I'm learing as I go, and my only background with programming is within the AutoCAD enviroment, and that was with Lisp.
It is going to be run for a presentation on 3d drawings. It will only allow the people to use the 3dorbit command from within Acad for a limited amout of time per drawing. It will be ran from the command line, and loaded in as a dll file.
Thanks again for all the help. I will let you know when I get it working.
Tim
|
|
|
|
|
It looks like the problem now is that it doesn't know how to get the current drawing NewDoc = DocMan.MdiActiveDocument; . Even if I put it in the long way NewDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; . It still won't be able to find it, and in turn execute the commands on it.
Is the timer taking control away from Acad? Is that why it can't find it?
If you have any ideas, I'm will to try them, as I'm totally lost now. Thanks.
Tim
|
|
|
|
|
Ooops!!:-> I missed that
Docman and NewDoc too should be declared as static if you want to share them between main and CancelCommand . Don't forget to call them by the class name.
Regards
|
|
|
|
|
No problem. I made the DocMan static, but didn't think I need to make the NewDoc static also. After I did this, it was able to read the NewDoc , and I was able to get a property, but when I tried to use the method CloseAndDiscard() it crashed with and unhandled access issue. I will have to look into this tomorrow, as I'm going home, and don't have Acad there yet, so can't test anything.
Thanks for all your help today Nader it is really appreciated!!
Tim
|
|
|
|
|
You're welcome.
And if you need something tommorow, just reply and I'll get an email notification.
Good luck with your demo.;)
Regards
|
|
|
|
|
I hate to have to ask you for somemore help, but I can't see to find an answer to what I thought would be a simple question.
How can you set the focus to an application? I think this might be a problem with my code. I think I need to set the focus back to Autocad in the event handler portion.
Thanks again.
-- modified at 13:54 Friday 15th September, 2006
Nevermind. It doesn't seem to work that way. Back to the drawing board. I found a way on this website.
http://www.personalmicrocosms.com/Pages/dotnettips.aspx?c=3&t=3[^]
Tim
|
|
|
|
|
Hello
Sorry I saw your post late. Here is the way -if you still want it-.
First, you can't do that using C# alone. you have to make some Windows API unmanaged functions. The functions import code is:
[DllImport("User32.dll", CharSet=CharSet.Auto)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
Now this loop will go through all top-level windows, check their title, then activate the one that has "Autocad" word on it:
foreach(Process P in Process.GetProcesses())
{
if (P.MainWindowTitle.Length > 0 && P.MainWindowTitle.IndexOf("Autocad") != -1)
SetForegroundWindow(P.MainWindowHandle);
}
One flow is that all windows that has "Autocad" word on it will be activated sequentily. If you know more word in a single phrase -ie. as a sentence- this should narrow this error margin.
Regards
|
|
|
|
|
Thank you for the code. I think I need to submit it to the Autocad people (they have a network of developers that help others) because I think I have gotten as far as I can with just your great C# help. I think it is an Autocad thing now, and if you don't use it (code for it, like it looks like you don't) then I don't think one would know how to fix it so that it will work.
Thanks again for your patience, and help. It's greatly appreciated (hope your not sick of reading this type of stuff, because it is sincere). If you want I will post the code that does work, sometimes people just like to see what was wrong. Who knows.
Tim
|
|
|
|
|
Hello
Thank you for your kind complements. I'm always happy to help you anytime.
What I got from your post is that your code didn't work out!! Why?? I though it did display that orbit thing, and all your problem was with the timer?? Sorry I don't have knowledge of Autocad, but I hope I helped you enough with the C# part!!
Anyway, if you still want to work out your code, just tell me what a non-autocad problem -if any- would be. If you found a working code, I'd be happy to see it.
Anyway, I wish you luck.
Regards
|
|
|
|
|
I have a Winform with a button. The Button Text is set to &RUN. When I open the application the Button does not Display RUN until I hit the Alt key. Is there a way to make this underlined when I open the app.
Thanks
Joe
|
|
|
|
|
That is a windows setting, it can't be changed in you app without effecting the entire system.
only two letters away from being an asset
|
|
|
|
|
|
Hello
There is a workaround the problem, even though it will be a diviation of the standards of windows programming - for example you can show your mainmenu at the bottom of your form, but is that right?
Anyway.. Handle the Paint event of your button and use e.Graphics object in the handler to draw the line at the appropriate coordinates.
Regards
|
|
|
|
|
Hi,
I am trying to change my form background image onClick from a button. I have this so far but it doesn't seem to be working and I can't workout how to do it!
this.BackgroundImage = (System.Drawing.Image.FromFile("theme\red.png"));
Can anyone point me in the correct direction?
Many Thanks,
Al
|
|
|
|
|
The \ character is an escape key; the string will take \r to mean a return character code. To specify a string with an actual \, you need to either use a double-slash or the @ symbol:
this.BackgroundImage = Image.FromFile("theme\\red.png");
or
this.BackgroundImage = Image.FromFile(@"theme\red.png");
|
|
|
|
|
|
Just to let you know, here is a list of escape sequences you might want to use/avoid.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Is there a way for me to convert my existing C# files to have .designer.cs files? I am working on a very large project and this would be a very useful change to our project. Are there any articles explaining how to do this by hand if there is no automatic converter?
|
|
|
|
|
I've never seen one myself, unfortunately. You *could* write something that would do this: basically create a new file on disk in the same folder as the original file, scan that file for the Dispose and InitializeComponent methods, then move them to the designer file. Shouldn't be too difficult.
|
|
|
|
|
I'm drawing text using TextOut and when I required text to be vertical I needed to use LogFont to set the orientation. Hovever when texting it on the origional function I made everytime it draws it, its slightly different and reall messed up. Like it will be much bigger and italic and striked outdespite the LOGFONT object saying otherwise.
Here's an image of what it looks like: http://www.draders.com/images/CreateFontIndirect.jpg[^]
The function is:
public static void DrawString(Graphics g, string s, Font Font, Color ForeColour, int x, int y) {<br />
IntPtr hdc = g.GetHdc();<br />
LOGFONT LF = new LOGFONT();<br />
Font.ToLogFont(LF);<br />
<br />
IntPtr fntNew = CreateFontIndirect(ref LF);<br />
IntPtr fntOld = SelectObject(hdc, fntNew);<br />
<br />
SetTextColor(hdc, RGB(ForeColour));<br />
SetBkMode(hdc, BackgroundMode.TRANSPARENT);<br />
TextOut(hdc, x, y, s, System.Text.Encoding.Default.GetByteCount(s));<br />
SelectObject(hdc, fntOld);<br />
DeleteObject(fntNew);<br />
g.ReleaseHdc(hdc);<br />
}
The logfont produced (using the default forms font) is:
LOGFONT
lfHeight: -11
lfWidth: 0
lfEscapement: 0
lfOrientation: 0
lfWeight: FW_NORMAL
lfItalic: 0
lfUnderline: 0
lfStrikeOut: 0
lfCharSet: SHIFTJIS_CHARSET
lfOutPrecision: OUT_DEFAULT_PRECIS
lfClipPrecision: CLIP_DEFAULT_PRECIS
lfQuality: DEFAULT_QUALITY
lfPitchAndFamily: FF_DONTCARE
lfFaceName: Microsoft Sans Serif
I noticed the height was negative and all examples I've seen set it to a positive value, so I tried setting it to 11 before calling CreateFontIndirect and that caused it to not draw at all.
The LOGFONT object and CreateFontIndirect function I used are:
[DllImport("gdi32")]<br />
internal static extern IntPtr CreateFontIndirect([In, MarshalAs(UnmanagedType.LPStruct)] ref LOGFONT lplf);<br />
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]<br />
internal class LOGFONT {<br />
public int lfHeight;<br />
public int lfWidth;<br />
public int lfEscapement;<br />
public int lfOrientation;<br />
public FontWeight lfWeight;<br />
public byte lfItalic;<br />
public byte lfUnderline;<br />
public byte lfStrikeOut;<br />
public FontCharSet lfCharSet;<br />
public FontPrecision lfOutPrecision;<br />
public FontClipPrecision lfClipPrecision;<br />
public FontQuality lfQuality;<br />
public FontPitchAndFamily lfPitchAndFamily;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]<br />
public string lfFaceName;<br />
}
Any help or ideas on what I'm doing wrong would be great!
|
|
|
|
|
Hi
i want to add User interface Wizard in my application
How it is possible
Please tell the sipmlest solution
Parshant
|
|
|
|
|
There are no wizard controls built into the System.Windows.Forms UI toolkit, however, there are several free ones, such as this one[^], available for download.
|
|
|
|
|