### Author Topic: Lab 3 reworked  (Read 2113 times)

0 Members and 1 Guest are viewing this topic.

#### CmdrDuh

• Automatic Duh Generator
• King Gator
• Posts: 4039
##### Lab 3 reworked
« on: May 24, 2006, 07:03:06 PM »
OK, so Kerry started this, but Im so far behind I need a refresher.  I obviously dont understand Ellispes very well.  What Im trying to do is use both of the ways to create an ellispe.  here is what I have.

Code: [Select]
Ellipse el = new Ellipse(center,Vector3d.ZAxis,new Vector3d(3,0,0),0.5,0,0);  // this works
Ellipse el = new Ellipse(); //center,Vector3d.ZAxis,new Vector3d(3,0,0),0.5,0,0);  // this doesn't
el.Center=center;
el.Normal=Vector3d.ZAxis;
el.MajorAxis= new Vector3d(3,0,0);
el.StartAngle=0;
el.EndAngle=0;
If you take out the // on line 1, it all works. (You wouldnt need any other lines if // are removed)
But, with the comments, Im trying to manually put in the values passed in line one.  It pukes on the MajorAxis and Normal.  Why?
« Last Edit: May 24, 2006, 07:33:47 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### CmdrDuh

• Automatic Duh Generator
• King Gator
• Posts: 4039
##### Re: Lab 3 reworked
« Reply #1 on: May 24, 2006, 07:05:01 PM »
Normal and MajorAxis are readonly, yet assignable in line 1???
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### MickD

• Gator
• Posts: 3314
• (x-in)->[process]->(y-out)
##### Re: Lab 3 reworked
« Reply #2 on: May 24, 2006, 07:34:39 PM »
That's because these private members are initialised in the constructor, when you are trying to assign or read these values they are set/get through property methods which can be created to only set or get if required to protect the inner workings of an object.
hth.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

#### CmdrDuh

• Automatic Duh Generator
• King Gator
• Posts: 4039
##### Re: Lab 3 reworked
« Reply #3 on: May 25, 2006, 10:08:33 AM »
Thanks Mick, that makes sense.  So if I understand you right, you cant create using those, but you could modify later using set/get statements.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### CmdrDuh

• Automatic Duh Generator
• King Gator
• Posts: 4039
##### Re: Lab 3 reworked
« Reply #4 on: May 25, 2006, 11:16:36 AM »
Next question, why would I get this error?
Quote
C:\CSHARP\LAB3\LAB3\Class.cs(100): An object reference is required for the nonstatic field, method, or property 'ClassLibrary.TEP_Class.CreateLayr()'
this is what I'm trying to do
Code: [Select]
public ObjectId CreateLayr()
{
ObjectId layerId;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor ;
Database db = HostApplicationServices.WorkingDatabase ;
Transaction trans = db.TransactionManager.StartTransaction();
LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId,OpenMode.ForWrite);
if (lt.Has("EmployeeLayer"))
{
layerId = lt["EmployeeLayer"];
}
else
{
LayerTableRecord ltr = new LayerTableRecord();
ltr.Name = "EmployeeLayer";
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 2);
}
trans.Commit();
trans.Dispose();
return layerId;
}

[CommandMethod("create")]
static public void createEmployee() // This method can have any name
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor ;
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans= db.TransactionManager.StartTransaction();
ObjectId objLay = CreateLayr();
.........
Its erring on the last line
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### Draftek

• Water Moccasin
• Posts: 1501
##### Re: Lab 3 reworked
« Reply #5 on: May 25, 2006, 11:49:31 AM »
Hi David,

Your CreateEmployee method is declared as 'static', meaning it can be accessed thru the class without creating an instance (object) of the class.

Your CraeteLayr method is not static. You cannot access it without creating an object of your class in the calling application.

If you change the CreateLayr method to 'Static', it will work as required.

I make the same mistake all the time....
Soli Deo Gloria

#### CmdrDuh

• Automatic Duh Generator
• King Gator
• Posts: 4039
##### Re: Lab 3 reworked
« Reply #6 on: May 25, 2006, 12:09:29 PM »
ok, while that made sense, why does the Adesk version look the same as mine?  Their calling function was not static, so it worked?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### CmdrDuh

• Automatic Duh Generator
• King Gator
• Posts: 4039
##### Re: Lab 3 reworked
« Reply #7 on: May 25, 2006, 12:10:34 PM »
To confirm what i was just babbling about, I removed the static from both of my functions, and it worked.  So should they be static?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### Bobby C. Jones

• Swamp Rat
• Posts: 514
• Cry havoc and let loose the dogs of war.
##### Re: Lab 3 reworked
« Reply #8 on: May 25, 2006, 01:07:52 PM »
To confirm what i was just babbling about, I removed the static from both of my functions, and it worked.  So should they be static?
static vs. instance is design decision that you'll need to make.  For a utility method like CreateLayer() you'll most likely want it to be static.  You call a static method like this

Code: [Select]
<className>.CreateLayer();
Bobby C. Jones

#### MickD

• Gator
• Posts: 3314
• (x-in)->[process]->(y-out)
##### Re: Lab 3 reworked
« Reply #9 on: May 25, 2006, 06:00:37 PM »
Just to add to what Bobby said, when you create a static member variable or function it gets created in memory on loading and there will only ever be one instance of the static variable or function. This is handy as you can have your utility functions that really don't require creating an instance of a class. This is how you can declare global 'like' variables and functions.

For example, a Circle is a class but it may have many instances with different values for diameter say, so having 1 static diameter variable would make all circles the same size but if you wanted a generic function to say change the colour of a circle you could write it as static and do something like Circle.ChangeColor(mycircle); (not that you would though ).

So you could think of static variables and functions as global but really they are contained in a class hence
<className>.CreateLayer();
to avoid naming clashes in your assemblies.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”