.NET

.NET

Reply
Valued Contributor
87 Posts
0 Kudos
Registered: ‎03-06-2012
Post 1 of 13
Accepted Solution

Change Color, Line Type and Line weight without selecting any objects

491 Views, 12 Replies
03-09-2012 07:57 PM

Hi,

I am trying to Change the Color, Line Type and Line weight in Properties Pallete without selecting any objects, but i don't know how to do this.



Hi,

 

>> we can't reback to "ByLayer"

Why not, this code does not Work?

acDoc.Database.Celtype = "byLayer"

 

- alfred -

 

Alfred,

db.Celtype is an ObjectId

 

 

But this works for me too.

 

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcadColor = Autodesk.AutoCAD.Colors;
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
db.Celweight = LineWeight.LineWeight015;
db.Cecolor = AcadColor.Color.FromColorIndex(ColorMethod.ByAci, 1);
db.Celtype = db.ContinuousLinetype;
AcadApp.ShowAlertDialog("NOW WE'LL CHANGE THEM BACK.");
db.Celweight = LineWeight.ByLayer;
db.Cecolor = AcadColor.Color.FromColorIndex(ColorMethod.ByAci,256);
db.Celtype = db.ByLayerLinetype;

 

 

 Regards,

 

 

*Expert Elite*
4,620 Posts
920 Kudos
Registered: ‎07-22-2003
Post 2 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 10:00 PM in reply to: chockalingam

Those are controlled by the drawing's Current sysvars.

CECOLOR

CELTYPE

CELWEIGHT

Jeff_M, also a frequent Swamper
Valued Contributor
87 Posts
0 Kudos
Registered: ‎03-06-2012
Post 3 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 10:06 PM in reply to: chockalingam

Can you guide me, to use this in .net code

Valued Mentor
278 Posts
22 Kudos
Registered: ‎11-29-2008
Post 4 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 10:14 PM in reply to: chockalingam

 

Untested

 

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

// AcadApp.SetSystemVariable(string name, object value)

	AcadApp.SetSystemVariable("CECOLOR", "BYLAYER")
	AcadApp.SetSystemVariable("CELTYPE", "ByLayer")
	AcadApp.SetSystemVariable("CELWEIGHT", -1)

 Regards

 

//-------------------------------------------------------

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Valued Contributor
87 Posts
0 Kudos
Registered: ‎03-06-2012
Post 5 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 10:28 PM in reply to: chockalingam

On using the above code,

 

AcadApp.SetSystemVariable("CECOLOR", "BYLAYER")- Results No Change

AcadApp.SetSystemVariable("CELTYPE", "ByLayer")- Results in "eInvalidInput" error

AcadApp.SetSystemVariable("CELWEIGHT", -1)- Results in "eInvalidInput" error

 


 

 

Valued Mentor
278 Posts
22 Kudos
Registered: ‎11-29-2008
Post 6 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 10:55 PM in reply to: chockalingam

 

Works for me. ... see attached piccy.

 

Before and After.PNG

//-------------------------------------------------------

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Valued Contributor
87 Posts
0 Kudos
Registered: ‎03-06-2012
Post 7 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 11:01 PM in reply to: chockalingam

I don't know why it is not working for me.....

But i got the solution in another way, my solution code follows,

 

Using lock As DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Using acTrans As Transaction = acDoc.Database.TransactionManager.StartTransaction()
acDoc.Database.Celweight = LineWeight.LineWeight015
acDoc.Database.Cecolor = Autodesk.AutoCAD.Colors.Color.FromColor(Color.Red)
Dim acLineTypTbl As LinetypeTable
acLineTypTbl = acTrans.GetObject(acDoc.Database.LinetypeTableId, OpenMode.ForRead)
Dim sLineTypName As String = "Continuous"
If acLineTypTbl.Has(sLineTypName) = True Then

'' Set the linetype Center current
acDoc.Database.Celtype = acLineTypTbl(sLineTypName)
'' Save the changes

End If
acTrans.Commit()
End Using
End Using

Valued Contributor
87 Posts
0 Kudos
Registered: ‎03-06-2012
Post 8 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 11:15 PM in reply to: chockalingam

But the Only Issue in above code is we can't reback to "ByLayer"

Valued Mentor
278 Posts
22 Kudos
Registered: ‎11-29-2008
Post 9 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 11:35 PM in reply to: chockalingam

 

Please clarify your last post. ??

 

//--------

And the code you posted is different to your initial question  ... but I see how I could confuse your intent.

//-------------------------------------------------------

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

*Expert Elite*
9,836 Posts
1,219 Kudos
Registered: ‎06-29-2007
Post 10 of 13

Re: Change Color, Line Type and Line weight without selecting any objects

03-09-2012 11:47 PM in reply to: chockalingam

Hi,

 

>> we can't reback to "ByLayer"

Why not, this code does not Work?

acDoc.Database.Celtype = "byLayer"

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!