Re: VSTA in Addin Workspace
Hi Luca,<br><br>the problem here is, that inside of the "Creator" class, no constructor with 1 parameter exists.<br>Per default, every class in C# has a constructor without parameters, which gets called whenever an instance of this class gets created. The default constructor always exists and does not need to be programmed.<br><br>In your case, you want to forward the reference of a zenon project to your constructor class, which is done in the constructor (best practice). That's what you do here:<br><font face="Consolas">Creator MyCreator = </font><code class="csharp keyword" style="background-attachment: scroll; background-clip: border-box; background-color: transparent; background-image: none; background-origin: padding-box; background-position-x: 0%; background-position-y: 0%; background-repeat: repeat; background-size: auto; border-bottom-color: rgb(0, 102, 153); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-bottom-style: none; border-bottom-width: 0px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 102, 153); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 102, 153); border-right-style: none; border-right-width: 0px; border-top-color: rgb(0, 102, 153); border-top-left-radius: 0px; border-top-right-radius: 0px; border-top-style: none; border-top-width: 0px; bottom: auto; box-sizing: content-box; color: rgb(0, 102, 153); float: none; font-family: &quot;Consolas&quot;,&quot;Bitstrea m Vera Sans Mono&quot;,&quot;Courier New&quot;,Courier,monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 700; height: auto; left: auto; letter-spacing: normal; line-height: 14.3px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: auto; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: static; right: auto; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; top: auto; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; width: auto; word-spacing: 0px;">new</code><span style='display: inline !important; float: none; background-color: rgb(255, 255, 255); color: rgb(62, 62, 62); font-family: "Consolas","Bitstream Vera Sans Mono","Courier New",Courier,monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 14.3px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-spacing: 0px;'> </span><code class="csharp plain" style="background-attachment: scroll; background-clip: border-box; background-color: transparent; background-image: none; background-origin: padding-box; background-position-x: 0%; background-position-y: 0%; background-repeat: repeat; background-size: auto; border-bottom-color: rgb(0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-bottom-style: none; border-bottom-width: 0px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; border-top-color: rgb(0, 0, 0); border-top-left-radius: 0px; border-top-right-radius: 0px; border-top-style: none; border-top-width: 0px; bottom: auto; box-sizing: content-box; color: rgb(0, 0, 0); float: none; font-family: &quot;Consolas&quot;,&quot;Bitstrea m Vera Sans Mono&quot;,&quot;Courier New&quot;,Courier,monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400; height: auto; left: auto; letter-spacing: normal; line-height: 14.3px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: auto; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: static; right: auto; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; top: auto; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; width: auto; word-spacing: 0px;">Creator(</code><code class="csharp keyword" style="background-attachment: scroll; background-clip: border-box; background-color: transparent; background-image: none; background-origin: padding-box; background-position-x: 0%; background-position-y: 0%; background-repeat: repeat; background-size: auto; border-bottom-color: rgb(0, 102, 153); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-bottom-style: none; border-bottom-width: 0px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 102, 153); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 102, 153); border-right-style: none; border-right-width: 0px; border-top-color: rgb(0, 102, 153); border-top-left-radius: 0px; border-top-right-radius: 0px; border-top-style: none; border-top-width: 0px; bottom: auto; box-sizing: content-box; color: rgb(0, 102, 153); float: none; font-family: &quot;Consolas&quot;,&quot;Bitstrea m Vera Sans Mono&quot;,&quot;Courier New&quot;,Courier,monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 700; height: auto; left: auto; letter-spacing: normal; line-height: 14.3px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: auto; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: static; right: auto; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; top: auto; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; width: auto; word-spacing: 0px;">this</code><code class="csharp plain" style="background-attachment: scroll; background-clip: border-box; background-color: transparent; background-image: none; background-origin: padding-box; background-position-x: 0%; background-position-y: 0%; background-repeat: repeat; background-size: auto; border-bottom-color: rgb(0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-bottom-style: none; border-bottom-width: 0px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; border-top-color: rgb(0, 0, 0); border-top-left-radius: 0px; border-top-right-radius: 0px; border-top-style: none; border-top-width: 0px; bottom: auto; box-sizing: content-box; color: rgb(0, 0, 0); float: none; font-family: &quot;Consolas&quot;,&quot;Bitstrea m Vera Sans Mono&quot;,&quot;Courier New&quot;,Courier,monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400; height: auto; left: auto; letter-spacing: normal; line-height: 14.3px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: auto; orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: static; right: auto; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; top: auto; vertical-align: baseline; -webkit-text-stroke-width: 0px; white-space: pre; width: auto; word-spacing: 0px;">.ActiveDocument);<br><br><span style="font-family:arial;">The problem in your case is, the your "Creator" class does not know what to do with the further parameter, as the class only knows the default constructor.<br>Means, you need to overload your constructor. This could look the following way:<br><br> &n bsp; public Creator(IProject zProject)<br> & nbsp; {<br> &nb sp; if (zProject == null)<br>   ; {<br> &nb sp; System.Diagnostics.Debug.Print("No zenon reference in Creator Constructor");<br> &n bsp; &nbs p; return;<br> &nb sp; }<br> &nb sp; myProject = zProject;<br> & nbsp; }<br> <br></span></code><span style="font-family:arial;">The overloading of the constructor (with similar code) should actually be mentioned in the training material. If not, please contact the training department of COPA-DATA.<br><br><br>Thanks and all the best for your further VSTA courses <br>Christian<br></span><br>
Re: VSTA in Addin Workspace
Dear Chris,
I've modified a little your code. Now it's like this:
public class Creator
{
private IProject myProject;
public Creator(IProject zProject)
{
if (zProject == null)
{
System.Diagnostics.Debug.Print("No zenon reference is passed");
}
myProject = zProject;
}
In this way I've declared a private IProject variable myProject then overloaded as you suggested me the class and in the call of the class now I can use a parameter
public void Macro_CreateFrameWithPosition()
{
Creator myCreator = new Creator(this.ActiveDocument);
myCreator.CreateFrame("MySecondFrame", 200, 600, 200, 600);
}
As I wrote, I've been watching the video and there is no passage where it's explained this overload method of the class, this is why I've encountered this little problem.
If this thing I've written (i mean the C# code) is right I go ahead with the course.
Thanks and I wait for your reply.
Luca