.NET

.NET

Reply
Valued Contributor
chockalingam
Posts: 86
Registered: ‎03-06-2012
Message 1 of 13 (487 Views)
Accepted Solution

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

487 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*
Jeff_M
Posts: 4,519
Registered: ‎07-22-2003
Message 2 of 13 (449 Views)

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
chockalingam
Posts: 86
Registered: ‎03-06-2012
Message 3 of 13 (445 Views)

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
KerryBrown
Posts: 278
Registered: ‎11-29-2008
Message 4 of 13 (437 Views)

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
chockalingam
Posts: 86
Registered: ‎03-06-2012
Message 5 of 13 (434 Views)

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
KerryBrown
Posts: 278
Registered: ‎11-29-2008
Message 6 of 13 (423 Views)

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
chockalingam
Posts: 86
Registered: ‎03-06-2012
Message 7 of 13 (418 Views)

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
chockalingam
Posts: 86
Registered: ‎03-06-2012
Message 8 of 13 (412 Views)

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
KerryBrown
Posts: 278
Registered: ‎11-29-2008
Message 9 of 13 (406 Views)

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*
Alfred.NESWADBA
Posts: 9,583
Registered: ‎06-29-2007
Message 10 of 13 (402 Views)

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
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.