AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Query PropertyAlteration AlterationType.LineWeight not working

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
657 Views, 7 Replies

Query PropertyAlteration AlterationType.LineWeight not working

Hello,

 

I am unable to get a Property Alteration of type AlterationType.AlterationLineWeight to work in .NET (C#).  Has anyone been successful with this specific alteration?

 

I am able to complete a lineweight alteration manually in the Map Explorer, and I am able to complete an AlterationType.AlterationLayer programmatically.  Using similar code for LineWeight fails, unforunately.  I've tried entering "0","0.00" and "0.00 mm" as values for the LineWeight Expression but the alteration does not occur.  If I add the "mm" suffix as it shows when I complete the alteration in the Map Explorer, it throws an error, as it must be a number, apparently.  The layers are imported, just the lineweight isn't modified.  I tried QueryModel.Execute and QueryModel.Run with the same result.  The code I'm using is below:

 

// Attach the DWG
ProjectModel pm = HostMapApplicationServices.Application.ActiveProject;
ProjectCollection pc = HostMapApplicationServices.Application.Projects;
DrawingSet ds = pm.DrawingSet;

AttachedDrawing attachDWG = ds.AttachDrawing(_tempPath);
                        
QueryModel qm = pm.CreateQuery();
qm.Clear();
                        
// Create the location condition
LocationCondition condLoc = new LocationCondition();
condLoc.Boundary = AllBoundary.Create();

QueryBranch qbLocation = QueryBranch.Create();
qbLocation.JoinOperator = JoinOperator.OperatorAnd;
qbLocation.AppendOperand(condLoc);

// Alter the lineweight to 0 
PropertyAlterationDefinition paDef = qm.PropertyAlteration;
PropertyAlteration paLW = paDef.AddAlteration(AlterationType.AlterationLineWeight);
paLW.Expression = "0";
qm.EnablePropertyAlteration(true);
                        
// Run the query
qm.Define(qbLocation);
qm.Mode = QueryType.QueryDraw;
qm.Run();
//ObjectIdCollection idCol=qm.Execute(ds); //Same Result

// Detach the DWG
ds.DetachDrawing(attachDWG.AliasPath);
qm.Clear();

 If anyone has a LineWeight alteration working, I'd appreciate any insight you can provide.  Thanks!

7 REPLIES 7
Message 2 of 8
hence_the_name
in reply to: Anonymous

Hi,

 

Lineweight is coded like this:

 

ByLineWeightDefault = -3,
ByBlock = -2,
ByLayer = -1,
LineWeight000 = 0,
LineWeight005 = 5,
LineWeight009 = 9,
LineWeight013 = 13,
LineWeight015 = 15,

....

 

So, don't use "0","0.00" and "0.00 mm" as values.

 

Rob

http://raumpatrouille3d.blogspot.ch/
Message 3 of 8
Anonymous
in reply to: hence_the_name

Thanks for the information, that's helpful.  It needs to be a sting, so I tried setting Expression="LineWeight000", but got the same result.

Message 4 of 8
hence_the_name
in reply to: Anonymous

Hi,

it is an enumeration:

Autodesk.AutoCAD.DatabaseServices.LineWeight Enumeration

So you would use it like this:

Expression= LineWeight.LineWeight000;

Rob
http://raumpatrouille3d.blogspot.ch/
Message 5 of 8
Anonymous
in reply to: hence_the_name

Thanks for the help.  I was unaware of that enumeration.  The enumeration results in an integer, so adding.ToString() produces a runtime error.  "LineWeight000"  and "0.00 mm" also produce the error as I think it wants a number within the string and no text.  I'm sure it's something simple I'm missing.

paLW.Expression = Autodesk.AutoCAD.DatabaseServices.LineWeight.LineWeight000; // Won't compile wrong datatype

paLW.Expression = Autodesk.AutoCAD.DatabaseServices.LineWeight.LineWeight000.ToString(); // Throws Autodesk.Gis.Map.MapException

paLW.Expression = "LineWeight000"; // Throws Autodesk.Gis.Map.MapException

paLW.Expression="0.00 mm"; // Throws Autodesk.Gis.Map.MapException

paLW.Expression="0.00"; // No error, doesn't work
paLW.Expression="2"; // No error, doesn't work.
Message 6 of 8
hence_the_name
in reply to: Anonymous

Hi,

I didn't look at your code - I only noticed that you tried to apply a lineweight as number altough it is an enumeration.

I now looked at Map API docs and it says :

"The property describes the alteration. It can be a literal value of the appropriate type or a Visual LISP statement that resolves to such a value. Note that TextAlteration and HatchAlteration, which are subclassed from PropertyAlteration, inherit this function without overloading it. For the TextAlteration subclass, the expression is the text for the text alteration. For the HatchAlteration subclass, it is the name of a hatch pattern for the hatch alteration. "

So - I dont know what that means. I created a property alteration query in Map and saved it but it didn't look like anything you could put into your code ((ade_altpdefine "LineWeight" "0.90 mm"))
Have you looked at Map API DevSamples - there is one for Map query : Map ObjectARX SDK 2013\Map Samples\DotNet\QueryViewCS

Sorry, I dont have anything else,

Rob
http://raumpatrouille3d.blogspot.ch/
Message 7 of 8
Anonymous
in reply to: hence_the_name

I appreciate the amount of time you spent looking into this.  I tried setting Expression="((ade_altpdefine \"LineWeight\" \"0.90 mm\"))", and it did not work, but it did not throw an error, interestingly.  So you must be able to set the Expression to a LISP statement.  I tried guessing at a few other statements in parenthesis, but it didn't work.  If I come across something that works and modifies the lineweight, I'll post it here.  Thanks Robert_Fritz!

Message 8 of 8
Anonymous
in reply to: Anonymous

qm.Define(qbLocation);
qm.Mode = QueryType.QueryDraw;
//qm.Run(); //Same Result
ObjectIdCollection idCol=qm.Execute(ds);
// Loop each entity, changing the lineweight. 
foreach (ObjectId id in idCol)
{
         var ent = (Entity)tr.GetObject(id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite);
         ent.LineWeight = 0;
}

Looping through the resulting entities and changing the lineweight seems to work for my purposes.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost