.NET

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

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

458 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,384
Registered: ‎07-22-2003
Message 2 of 13 (420 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: 82
Registered: ‎03-06-2012
Message 3 of 13 (416 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: 269
Registered: ‎11-29-2008
Message 4 of 13 (408 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

 

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

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

Valued Contributor
chockalingam
Posts: 82
Registered: ‎03-06-2012
Message 5 of 13 (405 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: 269
Registered: ‎11-29-2008
Message 6 of 13 (394 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

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

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

Valued Contributor
chockalingam
Posts: 82
Registered: ‎03-06-2012
Message 7 of 13 (389 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: 82
Registered: ‎03-06-2012
Message 8 of 13 (383 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: 269
Registered: ‎11-29-2008
Message 9 of 13 (377 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.

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

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

*Expert Elite*
Alfred.NESWADBA
Posts: 9,070
Registered: ‎06-29-2007
Message 10 of 13 (373 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
-------------------------------------------------------------------------
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.