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!
Solved! Go to Solution.
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!
Solved! Go to Solution.
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
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
Thanks for the information, that's helpful. It needs to be a sting, so I tried setting Expression="LineWeight000", but got the same result.
Thanks for the information, that's helpful. It needs to be a sting, so I tried setting Expression="LineWeight000", but got the same result.
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.
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.
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!
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!
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.
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.