Resource creation in a Addin of MS Project

D

dotnet-force

Hi all,

I'm using MS Project 2002 and create a COM Addin in C#.

I want to add a new resource to the current project.
So I used :
currentProject.Resources.Add(resName, idx);

It works fine.
But the new resource is an exact copy of an other resource except the
name. So I would like to make a copy of the initial resource (with a new
ID) and then change the name of the new resource.

Can someone tell if I can do that and how ?

Thanks for help.
Pascal Lenormand
ILOG.
 
W

Wei-Dong Xu [MSFT]

Hi Pascal,

From my understanding to this issue, the resource you mentioned here is
bitmap, icon etc which is included in your com-addin project files. You are
going to create your own resource for the Project addin.
If my understanding is not right, plesae feel free to correct me.

I'd suggest you can create the resource file in your add-in .net project.
Visual Studio.Net will help you a lot in the resource creation. The kb
article 820659 will provide the assistance for you regarding this.
820659 HOW TO: Use Microsoft Visual Basic .NET to Create a Resource File by
http://support.microsoft.com/?id=820659

Please feel free to let me know if you have any further questions.

Does this answer your question? Thank you for using Microsoft NewsGroup!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

dotnet-force

Hi,

There is a misunderstanding between us. I will try to be clearer.
I'm not speaking about resource such icon, bitmap included in my addin

The resource I was spoken are the resource which can affected to task in
MS Project.

I use the following code using the API of MS Project interopability
assembly :

Microsoft.Office.Interop.MSProject.Application appli = ...
Microsoft.Office.Interop.MSProject.Project project = appli.ActiveProject
Microsoft.Office.Interop.MSProject.Resource oldRes = ....
Microsoft.Office.Interop.MSProject.Resource newRes =
project.Resources.Add("new res", 0);
// Then code to copy all informations in oldRes to newRes
.....

But as I want to create a copy of oldRes (with all information such
cost, calendar, ...), I have to get many info from oldRes and copy it to
newRes.
So what I want to do is to create a copy of oldRes and then change the
name of newRes.

Here is the code I would like to use (but I haven't the API):
Microsoft.Office.Interop.MSProject.Application appli = ...
Microsoft.Office.Interop.MSProject.Project project = appli.ActiveProject
Microsoft.Office.Interop.MSProject.Resource oldRes = ....
Microsoft.Office.Interop.MSProject.Resource newRes = new
Microsoft.Office.Interop.MSProject.Resource(oldRes)
newRes.Name = "new res"

Thanks for your help.
Pascal Lenormand
ILOG
 
D

dotnet-force

Hi,

Do you have any news about this question ?

An other solution for my pb could be to copy the current project. But
it's the same : I don't know how to copy a project with the API.

Perhaps you could give me some information.

Thanks.
Pascal Lenormand
ILOG
 
C

Chris McConnell [MSFT]

Hello Pascal,

Did you not get the following response?

Start of the earlier posting:
Newsgroups: microsoft.public.office.developer.com.add_ins
From: (e-mail address removed) (Chris Jensen [MSFT])
Date: Fri, 23 Jan 2004 22:36:18 GMT
Subject: RE: Resource creation in a Addin of MS Project

Hello Pascal,

You'll need to change the contents of the "Name" field of the row.

Here is an idea of the code to do that

private MSProject.Application oApp;
private MSProject.Project oProj;
private Missing oMissing = Missing.Value;
. . .

private void OpenProject_Click(object sender, System.EventArgs e)
{
oApp = new MSProject.Application();
oApp.FileOpen("C:\\ProjectA.mpp",
false, // ReadOnly
oMissing, // merge
oMissing, // taskinformation
oMissing, // Table
oMissing, // Sheet
oMissing, // noAuto
oMissing, // userID
oMissing, // DatabasePassword
oMissing, // FormatID
oMissing, // map
0, // OpenPool
oMissing, // password
oMissing, // writeResPassword
oMissing, // ignoreReadOnlyRecommended
oMissing); // XMLName - 16 arguments
oApp.Visible = true;
oProj = oApp.ActiveProject;
object oView = "Resource &Sheet";
object oRes = "Nuclear Physicist";
object oRes1;
object oRes2 = "Brain Surgeon";
int idx = 1;
oApp.ViewApply(oView,oMissing,oMissing);
oProj.Resources.Add(oRes,(object)idx); //(object)
idx);
oApp.SelectResourceField(0, "Name",oMissing,oMissing, oMissing,
oMissing,oMissing);
oRes1 = oApp.ActiveCell.Text;
MessageBox.Show("Name already set = " + oRes1);
idx = idx + 1;
oProj.Resources.Add(oRes2,(object)idx);

oApp.SelectResourceField(1, "Name",oMissing,oMissing, oMissing,
oMissing,oMissing);
oRes1 = oApp.ActiveCell.Text;
MessageBox.Show("Second Name set = " + oRes1);

oApp.SelectResourceField(0,"Cost per
Use",oMissing,oMissing,oMissing,oMissing,oMissing);
oApp.SetResourceField("Cost per
Use","$145.00",oMissing,oMissing,oMissing,oMissing);
oRes1 = oApp.ActiveCell.Text;
MessageBox.Show("Resource value = " + oRes1);


}

End of earlier posting.

When you add a resource you provide one argument - i.e. the name. All the
other fields are set to default values, which will be $0.00 or 0 or blank.
You have to supply values for each of the other fields. The example above
sets the value of the "Cost per Use" field. You can learn the exact field
names by viewing the Resource sheet, then holding your mouse over the
column headings. The column heading for Cost per Use is shown as Cost/Use.
That latter will cause the code to show an error, because Cost/Use isn't a
field name. When you hold your mouse over the gray column heading that
says Cost/Use you'll see a tool-tip that says Cost per Use. You can get the
names of each of the other fields the same way. You may not need to supply
values for each and every field, but for those you wish to change you'll
need code similar to that in the example above.

When you add a second resource, don't use the original name, but rather,
supply a new name for the new resource. In the example above the first
resource was Nuclear Physicist. The next resource was named Brain Surgeon.
You don't need to create a second Nuclear Physicist resource, then change
its name (although you can do that if you wish).

I hope this gives you the information you need.

Chris Jensen (Microsoft Corporation)
 
D

dotnet-force

Chris said:
Did you not get the following response?

No I didn't get it and I didn't see it in the newsgroup. I didn't check
(e-mail address removed) email address because of spam. So please answer in
the newsgroup and if needed, I would give a valid email address.
When you add a resource you provide one argument - i.e. the name. All the
other fields are set to default values, which will be $0.00 or 0 or blank.
You have to supply values for each of the other fields. The example above
sets the value of the "Cost per Use" field.

It's quite long to do that because every time you change the selected
cell of Project and get the value of the active cell.

Could you tell me if there is a 'copy constructor' for MS Project
objects (such as resource, tasks, ...) ?
If I was in C++ or C# with classes, I would write :

int idx = 1;
Resource res1 = oProj.Resources.Add("Res1",(object)idx);
idx++;
Resource res2 = new Resource(res1, idx);
res2.Name = "Res2";

So is it possible or not ?

An other question which is in the same topic.
Is it possible to duplicate the current project of the MSProject
application ?

Thanks for your help.
Pascal Lenormand
ILOG
 
C

Chris McConnell [MSFT]

Hello Pascal,

There's no copy-constructor for MSProject,

The easiest way to duplicate a project is to open it, then save it under a
different name - ideally this will be the name you want for the new
project.

When you do this you probably will need to adjust the start date, and/or
other anniversary dates.

This won't change the original project.

Chris Jensen(Microsoft)
 
D

dotnet-force

Hi,
Hello Pascal,

There's no copy-constructor for MSProject,

Ok thank you.
The easiest way to duplicate a project is to open it, then save it under a
different name - ideally this will be the name you want for the new
project.

When you do this you probably will need to adjust the start date, and/or
other anniversary dates.

This won't change the original project.

I already thought to this workaround, but I prefer to have your answer
before going with this solution.
Chris Jensen(Microsoft)

Thanks for your help.

Pascal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top