Given an arbitrary array of kineticjs objects there a way to get the object type?
var ary = new Array();
ary[0] = "Circle Obj";
ary[1] = "rect Obj";
ary[2] = "arc Obj";
ary[0] = "Circle Obj";
Please comment
Yes, use myObject.className
ary[0]=new Kinetic.Circle({...});
console.log(ary[0].className); // returns "Circle"
Related
I am learning groovy, I am using the documentation and some youtube videos. I want for testing to find out how to declare an array of objects, but that array will have a x number of objects depending on some stuff. Here is what I tried:
class Issue {
String type = ""
String severity = ""
String linestart = ""
String filename = ""
String meesage = ""
}
def test(){
Issue[] Issues = new Issue[5]
Issues[0].type = "error"
println Issues[0].type
}
test()
what I get:
Caught: java.lang.NullPointerException: Cannot set property 'type' on null object
java.lang.NullPointerException: Cannot set property 'type' on null object
I assume my array does not have 5 Issues objects inside, and that is why is trying to set on null object. How would be the right syntax to do so?
You are right- all the values are initially null. You have to first create instances of Issue and assign it to the array elements,
Issues[0] = new Issue()
Issues[0].type = "error"
alternatively, using "groovy" syntax,
Issues[0] = new Issue(type: "error")
I am strugglying with a problem that is to access the reference of the end point of a pipe curve to then create a dimension in the model, by the method doc.Create.Dimension().I already tried to use the Curve.EndPointReference(int index) method but it returns only null value. Can anyone help how to access this information ?
Also discussed and answered here by Fair59:
https://forums.autodesk.com/t5/revit-api-forum/endpointreference/td-p/7131328
The answer is also pointed to from The Building Coder:
http://thebuildingcoder.typepad.com/blog/2011/10/retrieving-duct-and-pipe-endpoints.html#comment-3344122037
Fair59's answer:
You probably are using the LocationCurve to find the reference. You need to use the "reference" Curve/Line that is part of the Element.Geometry.
Selection sel = this.ActiveUIDocument.Selection;
Element elem = doc.GetElement(sel.GetElementIds().FirstOrDefault());
Options opt = new Options();
opt.ComputeReferences = true;
opt.IncludeNonVisibleObjects = true;
opt.View = doc.ActiveView;
Reference ptRef =null;
foreach( var geoObj in elem.get_Geometry(opt) )
{
Curve cv = geoObj as Curve;
if (cv==null) continue;
ptRef = cv.GetEndPointReference(0);
}
if (ptRef!=null)
{
TaskDialog.Show("debug",ptRef.ConvertToStableRepresentation(doc));
}
I think you should try something like
yourPipe.Location.Curve.GetEndPoint(1)
This will give you the XYZ object of the end point of your curve.
Regards,
Arnaud.
I have a method that accepts two parameters. Projecthealthnotes is my model.
I will like to compare objprojHealth with the getRow object that I am retrieving from the database.
If they are the same no need to call SaveChanges() and if not the same then call SaveChanges()
How can I compare these two objects and check whether they are the same?
public string WriteProgressHealthInfoToDb(Projecthealthnotes objprojHealth, string typeOfOperation)
{
using (var dbCntxt = new PPMSEntities1())
{
tbl_Project_Status_MSTR psmTable;
var convertedId = Convert.ToInt64(objprojHealth.Id);
var getRow = dbCntxt.tbl_Project_Status_MSTR.Single(m => m.ProjectStatusID == convertedId);
getRow.RecentProgress = objprojHealth.Recentprogress;
getRow.ObstaclesRisks = objprojHealth.Obstaclesrisk;
getRow.NextSteps = objprojHealth.Nextsteps;
getRow.ForWeekEnding = Convert.ToDateTime(objprojHealth.Weekendingdate);
getRow.BudgetHealth = Translator(objprojHealth.BudgetHealth);
getRow.TeamHealth = Translator(objprojHealth.TeamHealth);
getRow.RiskHealth = Translator(objprojHealth.RiskHealth);
getRow.ArtifactHealth = Translator(objprojHealth.BenefitHealth);
getRow.ScopeHealth = Translator(objprojHealth.ScopeHealth);
getRow.ScheduleHealth = Translator(objprojHealth.ScheduleHealth);
getRow.Phase = objprojHealth.Phase;
getRow.ReportingPeriod = Convert.ToInt16(objprojHealth.Reportingperiod);
//dbCntxt.Entry(getRow).State = System.Data.Entity.EntityState.Modified;
dbCntxt.SaveChanges();
return "success";
}
The only way to do this is to write a function that uses reflection to compare each property. Depending on your object you may have to do something a little more complex if it has nested reference types. The link below has some examples
http://www.sidesofmarch.com/index.php/archive/2007/08/03/use-reflection-to-compare-the-properties-of-two-objects/
I have a string var dictAsString:String = '["foo" : 123, "bar" : 456]' that I want to convert to a Dictionary (or NSDictionary, I'm not particular.) I've tried
var dictAsObj:AnyObject = dictAsString as AnyObject
var dictAsDict:NSDictionary = dictAsObj as NSDictionary
but that doesn't work. I've also tried
var dictAsDict:NSDictionary = NSDictionary(objectsAndKeys: dictAsString)
and
var dictAsObj:AnyObject = dictAsString as AnyObject
var dictAsDict:NSDictionary = NSDictionary(objectsAndKeys: dictAsObj)
Nothing seems to work, and I can't seem to find any help in the documentation. Any ideas?
That string resembles a JSON object.
You could replace the square brackets with curly brackets and use NSJSONSerialization class to get a dictionary out of it.
Worst case scenario, you should write a little parser.
I suggest using Ragel.
Both tasks are an overkill for a string like that, though.
Yet another newbie SubSonic/ActiveRecord question. Suppose I want to insert a couple of records, currently I'm doing this:
using (var scope = new System.Transactions.TransactionScope())
{
// Insert company
company c = new company();
c.name = "ACME";
c.Save();
// Insert some options
company_option o = new company_option();
o.name = "ColorScheme";
o.value = "Red";
o.company_id = c.company_id;
o.Save();
o = new company_option();
o.name = "PreferredMode";
o.value = "Fast";
o.company_id = c.company_id;
o.Save();
scope.Complete();
}
Stepping through this code however, each of the company/company_option constructors go off and create a new myappDB object which just seems wasteful.
Is this the recommended approach or should I be trying to re-use a single DB object - and if so, what's the easiest way to do this?
I believe you can use the same object if you want to by setting its IsNew property to true, then change its data properties, save it again, repeat. Easy enough.
I 'm not so sure that you should bother, though. It depends on how bad those constructors are hurting you.
In my eyes assigning multiple objects to a single var is never a good idea but thats arguable. I would do this:
// Insert some options
company_option o1 = new company_option();
o1.name = "ColorScheme";
o1.value = "Red";
o1.company_id = c.company_id;
o1.Save();
company_option o2 = new company_option();
o2.name = "PreferredMode";
o2.value = "Fast";
o2.company_id = c.company_id;
o2.Save();
I you are worried about performance, that shouldn't be a issue unless you want to insert or update many objects at once. And again, in this case the time used for inserting the data takes longer than for the object creation.
If you are worried about performance you can skip the object creation and saving part completly by using a Insert query:
http://www.subsonicproject.com/docs/Linq_Inserts
db.Insert.Into<company_option>(
x => x.name,
x => x.value,
x => x.company_id)
.Values(
"ColorScheme",
"Red",
c.company_id
).Execute();