Author Topic: Open drawing from listview  (Read 11562 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5218
Open drawing from listview
« on: February 27, 2007, 04:14:05 PM »
I'm trying to open up drawings from a list view.  I close the dialog, and then try to open them.  The drawing name gets passed, as I put in a message box to show this, but it keeps erroring out.  I'm have looked and tried many things, and none seem to work.  Any help is appreciated.

Here is the code I'm using.
Code: [Select]
void Button1Click(object sender, System.EventArgs e)
{
Close();
bool IsModel;
DocumentCollection DocCol = AcadApp.DocumentManager;
foreach (ListViewItem lvi in listView1.Items) {
ListViewItem.ListViewSubItemCollection lvsic = lvi.SubItems;
if (lvsic.Count > 1) {
try {
MessageBox.Show(lvsic[0].Text);
//Document tempDoc = DocCol.Open(lvsic[0].Text, true);
Document tempDoc = DocCol.Add(lvsic[0].Text);
if (string.Compare("Model", LayoutManager.Current.CurrentLayout) == 0) {
IsModel = true;
}
else IsModel = false;
StdScaleType ScaleType = (StdScaleType) Enum.Parse(typeof(StdScaleType), lvsic[4].Text, false);
MyPlottingPart(lvsic[1].Text, lvsic[2].Text, lvsic[3].Text, ScaleType, IsModel);
}
catch (System.Exception ex){
MessageBox.Show(ex.ToString());
}
}
}
}
Here are the picks of the two errors.
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: Open drawing from listview
« Reply #1 on: February 27, 2007, 04:35:34 PM »
Whats on line 380 and 381 ??

What is your CommandMethod declaration ?


Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Open drawing from listview
« Reply #2 on: February 27, 2007, 05:01:26 PM »
Whats on line 380 and 381 ??

What is your CommandMethod declaration ?



Those are the two different calls to try and open a document.  I made it a session command.
Tim

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

Please think about donating if this post helped you.

Alexander Rivilis

  • Bull Frog
  • Posts: 212
  • Programmer from Kyiv (Ukraine)

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Open drawing from listview
« Reply #4 on: February 27, 2007, 05:59:25 PM »
DocumentCollection.Open(dwgfileName) does not work when a modal dialog box is loaded
Thank Alexander.  I saw that, but hoped something new has been found out.  So how would I do this?

I'm guessing that I would make an array of all the objects in the listview, then close the dialog, and then procress the array.  I will see what I can come up with.  Do I have to unload the dialog?  not just close it?

Off to do some more research.  :-)
Tim

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

Please think about donating if this post helped you.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Open drawing from listview
« Reply #5 on: February 27, 2007, 06:07:57 PM »
I see you've been inspired by my Script Writer thread piccy there Tim.

Something along these lines:

Code: [Select]
string [] drgs;
using (MyDlg dlg = new MyDlg())
{
    // Show dialog here
    drgs = dlg.SomeMethodToGetDrgs();
}
// Process drgs here...

Cheers,
Glenn.
Me

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Open drawing from listview
« Reply #6 on: February 27, 2007, 06:47:01 PM »
I see you've been inspired by my Script Writer thread piccy there Tim.
I likey you're piccy.  :-)

Something along these lines:

Code: [Select]
string [] drgs;
using (MyDlg dlg = new MyDlg())
{
    // Show dialog here
    drgs = dlg.SomeMethodToGetDrgs();
}
// Process drgs here...

Cheers,
Glenn.
I'm not sure I know how to do this.  I tried code like this, that uses the dispose of the dialog, but get the same error messages.  I will try and use the 'using' and see if I can figure it out.  I call the dialog box from within a 'doclock' call, will this work?  I even commented it out, and it still didn't work.
Code: [Select]
void Button1Click(object sender, System.EventArgs e)
{
bool IsModel;
DocumentCollection DocCol = AcadApp.DocumentManager;
ListView.ListViewItemCollection lvic = listView1.Items;
string[,] tempArray = new string[lvic.Count, 5];
int i = 0;
foreach (ListViewItem lvi in lvic) {
ListViewItem.ListViewSubItemCollection lvsic = lvi.SubItems;
for (int j = 0; j < lvsic.Count; j++) {
tempArray[i,j] = lvsic[j].Text;
}
++i;
}
Close();
Dispose();
for (i = 0; i < (tempArray.Length / 5); ++i) {
if (tempArray[i,1] != null) {
try {
MessageBox.Show(tempArray[i,0]);
Document tempDoc = DocCol.Open(tempArray[i,0], true);
//Document tempDoc = DocCol.Add(tempArray[i,0]);
if (string.Compare("Model", LayoutManager.Current.CurrentLayout) == 0) {
IsModel = true;
}
else IsModel = false;
StdScaleType ScaleType = (StdScaleType) Enum.Parse(typeof(StdScaleType), tempArray[i,4], false);
MyPlottingPart(tempArray[i,1], tempArray[i,2], tempArray[i,3], ScaleType, IsModel);
}
catch (System.Exception ex){
MessageBox.Show(ex.ToString());
}
}
}
}
Tim

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

Please think about donating if this post helped you.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Open drawing from listview
« Reply #7 on: February 27, 2007, 06:55:47 PM »
To use a few words that are bandied about at the moment - you have to de-couple your UI and business logic :)
In other words, move all your processing code OUT of the form.

For instance, in your command class, fire the dialog inside a using statement, then before the using scope is exited, extract the data you need and truck on...which is what I showed previously.

Cheers,
Glenn.
Me

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Open drawing from listview
« Reply #8 on: February 27, 2007, 06:58:32 PM »
Once you solve this, I can guess what your next question will be  :evil:
Me

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Open drawing from listview
« Reply #9 on: February 27, 2007, 07:01:43 PM »
To use a few words that are bandied about at the moment - you have to de-couple your UI and business logic :)
In other words, move all your processing code OUT of the form.

For instance, in your command class, fire the dialog inside a using statement, then before the using scope is exited, extract the data you need and truck on...which is what I showed previously.

Cheers,
Glenn.
Okay.. I think I can get it from here.  I thought once I disposed of it, I could do the stuff within.

Once you solve this, I can guess what your next question will be  :evil:
No more questions....  :angel:
Tim

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

Please think about donating if this post helped you.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Open drawing from listview
« Reply #10 on: February 27, 2007, 07:10:33 PM »
Riddle me this grasshopper: How can you dispose of the form from INSIDE one of it's button handlers?
Me

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Open drawing from listview
« Reply #11 on: February 27, 2007, 07:20:28 PM »
Riddle me this grasshopper: How can you dispose of the form from INSIDE one of it's button handlers?
Uh...... you can't.... I guess...... Okay I will code it like you said.... I'm getting an 'eLocking' error.. maybe that is the cause... be right back.....  Oh yea!! Thanks....
Tim

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

Please think about donating if this post helped you.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Open drawing from listview
« Reply #12 on: February 27, 2007, 07:35:37 PM »
You won't need to lock to do the open btw...
Me

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Open drawing from listview
« Reply #13 on: February 27, 2007, 07:49:35 PM »
You won't need to lock to do the open btw...
I'm having other issues now Glenn.  I will work on this tomorrow, as it is time to go home.  Thanks for you help, I don't know if I would have gotten this far today without it.   :-)
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Open drawing from listview
« Reply #14 on: February 28, 2007, 05:14:16 PM »
So today I got it to open the drawings, print them (some times, this is the only erroring part now), and close the drawings.  I will post it when I get it complete enough to post.  The printing problems are wierd, and seem to have no rhyme or reason.

Off to study some more, and maybe understand the whole plotting thingy.  :-)
Thanks again!
Tim

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

Please think about donating if this post helped you.