Horizontal text in radius annotation. [Autocad] - autocad

I have two files open. One uses horizontal text in radius annotation (see the first picture). The second uses a straight line in radius annotation (see the second picture). I cannot find any difference in the settings of the two files. How do I get the second file's annotation like the first?
Picture 1:
Picture 2:

For a non-programmatic approach, you can import the 'Dimension Style' from one drawing to the other.
Using programming, just enumerate all properties of the style and compare. Below is a code for entities, but you need to adjust for Dim Style:
[CommandMethod("compEnt")]
public static void CmdCompareEntities()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ObjectId id1, id2;
//select the entities
PromptEntityResult per1, per2;
per1 = ed.GetEntity("\nSelect first entity: ");
id1 = per1.ObjectId;
per2 = ed.GetEntity("\nSelect second entity: ");
id2 = per2.ObjectId;
//some error check
if (per1.Status != PromptStatus.OK ||
per2.Status != PromptStatus.OK) return;
Database db =
Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction trans =
db.TransactionManager.StartTransaction())
{
//open the entities
Entity ent1 = (Entity)trans.GetObject(id1, OpenMode.ForRead);
Entity ent2 = (Entity)trans.GetObject(id2, OpenMode.ForRead);
Type entType1 = ent1.GetType();
Type entType2 = ent2.GetType();
//the two entities should be the same type
if (!entType1.Equals(entType2)) return;
//get the list of properties and iterate
System.Reflection.PropertyInfo[] props =
entType1.GetProperties();
foreach (System.Reflection.PropertyInfo prop in props)
{
try
{
//get both values property value
object val1, val2;
val1 = prop.GetValue(ent1, null);
val2 = prop.GetValue(ent2, null);
if (val1 != null & val2 != null)
{
//are equal?
if (!(val1.Equals(val2)))
{
//if not, write the value
ed.WriteMessage("\n{0} is different: {1} | {2}",
prop.Name, val1.ToString(), val2.ToString());
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
}
}
trans.Commit();
}
}
Source: Comparing properties of two entities

Related

dynamic sort columns doesn't work in linq

in linq i'm tring to create gridview with dynamic sort columns
can any one help me what is worng on below code and why it does't work
// i created this function to get column value which i need to sorty by
private static string GetReflectedPropertyValue( object subject, string field)
{
object reflectedValue = subject.GetType().GetProperty(field).GetValue(subject, null);
return reflectedValue != null ? reflectedValue.ToString() : "";
}
// this is my grid query
List<ticketSearchRes> tickets = new List<ticketSearchRes>();
// here i deteermined sort direction ascending or desc
bool asc = (gridViewInputsVM.SortDirection == "asc") ? true : false;
bool desc = (gridViewInputsVM.SortDirection != "asc") ? true : false;
IQueryable<ticketSearchRes> source = (from ticket in _db.TblTicket
where (searchRes.assignTic == 1) ? ticket.AssignedTo == CurrentuserId : true
where (searchRes.myTicket == 1 && searchRes.forOthers != 1) ? ticket.CreatedFor == CurrentuserId : true
orderby
asc ? GetReflectedPropertyValue(ticket, "TicketTitle") : "",
// here i need to get dynamic column which i need to sort by
desc ? GetReflectedPropertyValue(ticket, "TicketTitle") : "" descending // doesn't work
select new ticketSearchRes
{
title = (ticket.TicketTitle != null) ? ticket.TicketTitle.ToString() : "",
ticId = ticket.TicketId.ToString()
}).AsQueryable();
How I would solve this is;
The partial class TicketSearchResList is part that fills in the partial method CustomSort. CustomSort accepts a property name and a sort direction and uses Reflection to sort on the named property. So far it should be easy to follow.
public partial class TicketSearchResList : List<TicketSearchRes>
{
partial void CustomSort(string propertyName, string direction);
public void Dump()
{
CustomSort("TicketTitle", "desc");
foreach(var ticket in this)
Console.WriteLine(ticket.ToString()); // For demo purposes
}
}
public partial class TicketSearchResList {
private string propertyName;
private string direction;
partial void CustomSort(string propertyName, string direction)
{
this.propertyName = propertyName;
this.direction = direction;
Sort(Comparer);
}
private int Comparer(TicketSearchRes x, TicketSearchRes y)
{
int directionChanger = direction == "asc" ? 1 : -1;
try
{
PropertyInfo lhs = x.GetType().GetProperty(propertyName);
PropertyInfo rhs = y.GetType().GetProperty(propertyName);
object o1 = lhs.GetValue(x, null);
object o2 = rhs.GetValue(y, null);
if(o1 is IComparable && o2 is IComparable)
{
return ((IComparable)o1).CompareTo(o2) * directionChanger;
}
// No sort
return 0;
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message); // Should log something
return 0;
}
}
The comparison is done using Reflection in the Comparer method. The direction is
used to determine whether to multiply the result by 1 or -1. CompareTo returns
an integer where -1 means less than, 0 means equal to, and 1 means greater than. Thus, if
you multiply the result by -1, you change the direction of the sort.
Finally, the TicketSearchResList class inherits from List<TicketResearchRes>. As you can see, the Dump method calls CustomSort, which, if implemented, yields ordered output.
Also, have a look at the Sort Method documented here by Microsoft

Smartgwt ListGrid Group order

I have a ListGrid with 3 columns, one is hidden but it doesn't change anything to the problem.
I want to group on the value of the 3rd and hidden field, a date. When this Date is not present (null) I want to put the record in the "Actual Projects" group else they go in the "Closed projects" group.
It works BUT I want to have the group Actual Project first and I try a lot of thing with the sort direction of the field and the grid and also with baseTitle I return. It never change I always have the group with the non null value first.
Am I missing something? Is there somebody who experienced with group order?
final int groupClosed = 2;
final int groupActual = 1;
colonneDate.setGroupValueFunction(new GroupValueFunction() {
public Object getGroupValue(Object value, ListGridRecord record, ListGridField field, String fieldName, ListGrid grid) {
Date laDate = (Date)value;
if(laDate == null) {
return groupActual;
} else {
return groupClosed;
}
}
});
colonneDate.setGroupTitleRenderer(new GroupTitleRenderer() {
#Override
public String getGroupTitle(Object groupValue, GroupNode groupNode,
ListGridField field, String fieldName, ListGrid grid) {
final int groupType = (Integer) groupValue;
String baseTitle ="";
switch (groupType){
case groupActual:
baseTitle ="Actual Projects";
break;
case groupClosed:
baseTitle ="Closed Projects";
break;
}
return baseTitle;
}
});
listeGridProjets.setGroupByField("date");
I think you can sort your ListGrid on your colonneDate like this :
SortSpecifier sortSpecifier = new SortSpecifier("colonneDateFieldName", SortDirection.ASCENDING);
SortSpecifier[] sortSpecifiers = { sortSpecifier };
setSort(sortSpecifiers);

How to get out of repetitive if statements?

While looking though some code of the project I'm working on, I've come across a pretty hefty method which does
the following:
public string DataField(int id, string fieldName)
{
var data = _dataRepository.Find(id);
if (data != null)
{
if (data.A == null)
{
data.A = fieldName;
_dataRepository.InsertOrUpdate(data);
return "A";
}
if (data.B == null)
{
data.B = fieldName;
_dataRepository.InsertOrUpdate(data);
return "B";
}
// keep going data.C through data.Z doing the exact same code
}
}
Obviously having 26 if statements just to determine if a property is null and then to update that property and do a database call is
probably very naive in implementation. What would be a better way of doing this unit of work?
Thankfully C# is able to inspect and assign class members dynamically, so one option would be to create a map list and iterate over that.
public string DataField(int id, string fieldName)
{
var data = _dataRepository.Find(id);
List<string> props = new List<string>();
props.Add("A");
props.Add("B");
props.Add("C");
if (data != null)
{
Type t = typeof(data).GetType();
foreach (String entry in props) {
PropertyInfo pi = t.GetProperty(entry);
if (pi.GetValue(data) == null) {
pi.SetValue(data, fieldName);
_dataRepository.InsertOrUpdate(data);
return entry;
}
}
}
}
You could just loop through all the character from 'A' to 'Z'. It gets difficult because you want to access an attribute of your 'data' object with the corresponding name, but that should (as far as I know) be possible through the C# reflection functionality.
While you get rid of the consecutive if-statements this still won't make your code nice :P
there is a fancy linq solution for your problem using reflection:
but as it was said before: your datastructure is not very well thought through
public String DataField(int id, string fieldName)
{
var data = new { Z = "test", B="asd"};
Type p = data.GetType();
var value = (from System.Reflection.PropertyInfo fi
in p.GetProperties().OrderBy((fi) => fi.Name)
where fi.Name.Length == 1 && fi.GetValue(data, null) != null
select fi.Name).FirstOrDefault();
return value;
}
ta taaaaaaaaa
like that you get the property but the update is not yet done.
var data = _dataRepository.Find(id);
If possible, you should use another DataType without those 26 properties. That new DataType should have 1 property and the Find method should return an instance of that new DataType; then, you could get rid of the 26 if in a more natural way.
To return "A", "B" ... "Z", you could use this:
return (char)65; //In this example this si an "A"
And work with some transformation from data.Value to a number between 65 and 90 (A to Z).
Since you always set the lowest alphabet field first and return, you can use an additional field in your class that tracks the first available field. For example, this can be an integer lowest_alphabet_unset and you'd update it whenever you set data.{X}:
Init:
lowest_alphabet_unset = 0;
In DataField:
lowest_alphabet_unset ++;
switch (lowest_alphabet_unset) {
case 1:
/* A is free */
/* do something */
return 'A';
[...]
case 7:
/* A through F taken */
data.G = fieldName;
_dataRepository.InsertOrUpdate(data);
return 'G';
[...]
}
N.B. -- do not use, if data is object rather that structure.
what comes to my mind is that, if A-Z are all same type, then you could theoretically access memory directly to check for non null values.
start = &data;
for (i = 0; i < 26; i++){
if ((typeof_elem) *(start + sizeof(elem)*i) != null){
*(start + sizeof(elem)*i) = fieldName;
return (char) (65 + i);
}
}
not tested but to give an idea ;)

EF single entity problem

I need to return a single instance of my viewmodel class from my repository in order to feed this into a strongly-typed view
In my repository, this works fine for a collection of viewmodel instances:
IEnumerable<PAWeb.Domain.Entities.Section> ISectionsRepository.GetSectionsByArea(int AreaId)
{
var _sections = from s in DataContext.Sections where s.AreaId == AreaId orderby s.Ordinal ascending select s;
return _sections.Select(x => new PAWeb.Domain.Entities.Section()
{
SectionId = x.SectionId,
Title = x.Title,
UrlTitle = x.UrlTitle,
NavTitle = x.NavTitle,
AreaId = x.AreaId,
Ordinal = x.Ordinal
}
);
}
But when I attempt to obtain a single entity, like this:
public PAWeb.Domain.Entities.Section GetSection(int SectionId)
{
var _section = from s in DataContext.Sections where s.SectionId == SectionId select s;
return _section.Select(x => new PAWeb.Domain.Entities.Section()
{
SectionId = x.SectionId,
Title = x.Title,
UrlTitle = x.UrlTitle,
NavTitle = x.NavTitle,
AreaId = x.AreaId,
Ordinal = x.Ordinal
}
);
}
I get
Error 1 Cannot implicitly convert type
'System.Linq.IQueryable<PAWeb.Domain.Entities.Section>' to
'PAWeb.Domain.Entities.Section'. An explicit conversion exists
(are you missing a cast?)"
This has got to be simple, but I'm new to c#, and I can't figure out the casting. I tried (PAWeb.Domain.Entities.Section) in various places, but no success. Can anyone help??
Your query is returning an IQueryable, which could have several items. For example, think of the difference between an Array or List of objects and a single object. It doesn't know how to convert the List to a single object, which one should it take? The first? The last?
You need to tell it specifically to only take one item.
e.g.
public PAWeb.Domain.Entities.Section GetSection(int SectionId)
{
var _section = from s in DataContext.Sections where s.SectionId == SectionId select s;
return _section.Select(x => new PAWeb.Domain.Entities.Section()
{
SectionId = x.SectionId,
Title = x.Title,
UrlTitle = x.UrlTitle,
NavTitle = x.NavTitle,
AreaId = x.AreaId,
Ordinal = x.Ordinal
}
).FirstOrDefault();
}
This will either return the first item, or null if there are no items that match your query. In your case that won't happen unless the table is empty since you don't have a where clause.

How Can I Get the Identity Column Value Associated with a SubSonic 3 LinqTemplate Insert?

I am using SubSonic 3.0.0.3 along with the Linq T4 Templates. My ProjectRepository, for example, has the following two methods:
public int Add(Project item)
{
int result = 0;
ISqlQuery query = BuildInsertQuery(item);
if (query != null)
{
result = query.Execute();
}
return result;
}
private ISqlQuery BuildInsertQuery(Project item)
{
ITable tbl = FindTableByClassName();
Insert query = null;
if (tbl != null)
{
Dictionary<string, object> hashed = item.ToDictionary();
query = new Insert(_db.Provider).Into<Project>(tbl);
foreach (string key in hashed.Keys)
{
IColumn col = tbl.GetColumn(key);
if (col != null)
{
if (!col.AutoIncrement)
{
query.Value(key, hashed[key]);
}
}
}
}
return query;
}
Along with performing the insert (which works great), I'd really like to get the value of the auto-incrementing ProjectId column. For the record, this column is both the primary key and identity column. Is there perhaps a way to append "SELECT SCOPE_IDENTITY();" to the query or maybe there's an entirely different approach which I should try?
You can do this with the ActiveRecord templates which does all of the wiring above for you (and also has built-in testing). In your scenario, the Add method would have one line: Project.Add() and it would return the new id.
For your needs, you can try this:
var cmd=query.GetCommand();
cmd.CommandSql+=";SELECT SCOPE_IDENTITY() as newid";
var newID=query.Provider.ExecuteScalar(cmd);
That should work..
*Edit - you can create an ExtensionMethod for this on ISqlQuery too, to save some writing...

Resources