Select IFC Physical Simple Quantity of Wall - c#

I'm using XBim IFC libraries in order to get some info of a Building model elements.
Specifically, of IfcWall entities.
I have to acces Wall Base Quantities (lenght, height, width, etc.) but I cant reach those properties from IfcWall class.
I have this class:
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xbim.Ifc;
using Xbim.Ifc4.ActorResource;
using Xbim.Ifc4.DateTimeResource;
using Xbim.Ifc4.ExternalReferenceResource;
using Xbim.Ifc4.PresentationOrganizationResource;
using Xbim.Ifc4.GeometricConstraintResource;
using Xbim.Ifc4.GeometricModelResource;
using Xbim.Ifc4.GeometryResource;
using Xbim.Ifc4.Interfaces;
using Xbim.Ifc4.Kernel;
using Xbim.Ifc4.MaterialResource;
using Xbim.Ifc4.MeasureResource;
using Xbim.Ifc4.ProductExtension;
using Xbim.Ifc4.ProfileResource;
using Xbim.Ifc4.PropertyResource;
using Xbim.Ifc4.QuantityResource;
using Xbim.Ifc4.RepresentationResource;
using Xbim.Ifc4.SharedBldgElements;
namespace ProcesadorPremoldeado.IFC
{
public class IFCCalculos
{
public void CalculoPlacas(string fileName, XbimEditorCredentials editor)
{
using (var model = IfcStore.Open(fileName, editor))
{
using (var transaction = model.BeginTransaction("Quick start transaction"))
{
//get all Walls in the model
var ifcWallsList = model.Instances.OfType<IfcWall>();
foreach (var wall in ifcWallsList)
{
var prop = wall.PhysicalSimpleQuantities.Where(x=>x.Name=="Height");
}
transaction.Commit();
}
}
}
}
}
That lambda expression return me a row, correctly filtered by Name parameter, as this property is accessible.
But I cant access the property call "LengthValue", the strange thing is that the property is visible during debbugin if I put a breakpoint, under "prop" list in the foreach loop.
Anyone could give me an idea of what could be happening?
Thanks in advance!

This is because LengthValue is a property of IfcQuantityLength, but PhysicalSimpleQuantities are of supertype IfcPhysicalQuantity. You just need to select quantities of the right type
var height = wall.PhysicalSimpleQuantities
.OfType<IfcQuantityLength>()
.Where(x=>x.Name=="Height")?
.LengthValue;

Related

Acumatica validation error when using PXSelect

Every time I try to select a specific data record based on a column criteria Acumatica throws an error saying that the type name does not exist, when in the table it absolutely does.
Can someone tell me what I am doing wrong?
If I remove the "where" part of the statement, it validates fine; however that is not what I need to do.
Here is the error message
\App_RuntimeCode\CRActivityMaint.cs(34): error CS0426: The type name 'NoteID' does not exist in the type 'Contact'
Here is the code
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using PX.Common;
using PX.CS;
using PX.Data.EP;
using PX.Objects.CR;
using PX.Data;
using System;
using System.Collections;
using PX.Objects.GL;
using PX.Objects.PM;
using PX.Objects.CS;
using PX.Objects.Common.GraphExtensions.Abstract;
using System.Web.Compilation;
using PX.Objects;
using PX.Objects.EP;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
namespace PX.Objects.EP
{
public class CRActivityMaint_Extension : PXGraphExtension<CRActivityMaint>
{
protected void CRActivity_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
var task = (CR.CRActivity)e.Row;
var taskExt = task.GetExtension<CR.CRActivityExt>();
if (taskExt != null)
{
Contact contactInfo = PXSelect<Contact, Where<Contact.NoteID, Equal<Required<Contact.NoteID>>>>.Select(this.Base, 100862);
}
}
#region Event Handlers
#endregion
}
}```
NoteID is a GUID stored as an uniqueidentifier in SQL (Ex '5D0C3B2C-D87F-E411-BECA-00B56D0561C2'). I suggest you try using a GUID parameter.

What reference should I use for 'Data.ValueRange'?

I'm following a guide to write output data from Visual Studio into a google spreadsheet.
At the end of the guide there is a code block that I pasted inside my project:
using OpenQA.Selenium.Support.UI;
using System;
using NUnit.Framework;
using OpenQA.Selenium;
using System.Collections;
using System.Collections.Generic;
using Google.Apis.Sheets.v4;
using Google.Apis.Auth.OAuth2;
using System.IO;
using Google.Apis.Services;
using Newtonsoft.Json;
using WikipediaTests.Foundation_Class;
using System.Web;
using System.Data;
using Google.Apis.Sheets.v4.Data;
namespace AutomationProjects
{
[TestFixture]
public class TestClass : TestFoundation
{
public class SpreadSheetConnector
{
//Codeblock from guide pasted here!
}
[Test]
public void test1()
{
//Test case 1. Do XYZ...
}
}
}
In the code block included in the guide there is a section about creating a list and passing data into it:
// Pass in your data as a list of a list (2-D lists are equivalent to the 2-D spreadsheet structure)
public string UpdateData(List<IList<object>> data)
{
String range = "My Tab Name!A1:Y";
string valueInputOption = "USER_ENTERED";
// The new values to apply to the spreadsheet.
List<Data.ValueRange> updateData = new List<Data.ValueRange>();
var dataValueRange = new Data.ValueRange();
dataValueRange.Range = range;
dataValueRange.Values = data;
updateData.Add(dataValueRange);
Data.BatchUpdateValuesRequest requestBody = new Data.BatchUpdateValuesRequest();
requestBody.ValueInputOption = valueInputOption;
requestBody.Data = updateData;
var request = _sheetsService.Spreadsheets.Values.BatchUpdate(requestBody, _spreadsheetId);
Data.BatchUpdateValuesResponse response = request.Execute();
// Data.BatchUpdateValuesResponse response = await request.ExecuteAsync(); // For async
return JsonConvert.SerializeObject(response);
}
The problem is that I get an error for the 'Data.ValueRange' and the 'Data.BatchUpdateValuesRequest' :
CS0246 The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?)
I tried adding "System.Data" as a assembly reference to my project and then added it at the top (using). But it did not remove the error.
'Data.' seems to belong to "Google.Apis.Sheets.v4" but I have already added that reference as the guide instructed.
The only fix that gets rid of the error is adding Google.Apis.Sheets.v4 before every 'Data.' like this:
List<Google.Apis.Sheets.v4.Data.ValueRange>
But when I run my tests the output does not get exported to my spreadsheet. So I'm assuming this is not the correct solution. And also I'm assuming that the guide should have included this in the code block if it was necessary.
Could there be some other reference about 'Data' I need?
According to the documentation, the ValueRange Class depends of Sheets.v4.Data, so you should add:
using Google.Apis.Sheets.v4.Data;
Also, change:
List<Data.ValueRange> updateData = new List<Data.ValueRange>();
to:
List<ValueRange> updateData = new List<ValueRange>();

Linq and localhost, entity namespace is different than program namespace but still get error

I have tried to search for this but every example I find has a problem like them actually having the same namespace as their class or something.
I am simply trying to start using Linq. When I add new item Host is localhost. I have my database in Visualstudio and my project name is different than the DataContext name but I can't get it initialized. I get error:
'LinkedContext' is a namespace but is used like a type'
here is code...
namespace TryAgain
{
class Program
{
static void Main(string[] args)
{
LinkedContext db = new LinkedContext();
}
}
}
LinkedContext doesn't work? In settings of the Database Diagram it says the Entity Namespace is 'LinkedContext' So what am I missing. I thought I saw you could run that one line of code to connect your database that is already in VisualStudio due to adding a new item and then start playing with it? I just want to be able to practice with a database! Do stuff like:
var example = from x in example.Table
orderby x.field
select x;
you need using LinkedContext at the top of your file. the error you’re getting is telling you LinkedContext is a namespace but you’re treating like a type, ie a class. once you define it at the top you can then use the type that you need within that namespace.
added "using LinkedContext" to the top of code then also had to use LinkedDataContext not just LinkedContext:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LinkedContext;
namespace TryAgain
{
class Program
{
static void Main(string[] args)
{
LinkedDataContext db = new LinkedDataContext();
var example = from x in db.employees
orderby x.employee_id
select x;
foreach (var whatever in example)
{
Console.WriteLine(whatever.name);
}

Super-simple linq query still doesn't work

Trying to use Linq and the Entity Framework to make a super-simple lists database. The query runs, but it does not return the data I enter into it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using static System.Console;
namespace CheckList
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Building the list.");
using (var db = new ListContext())
{
ListItem socks = new ListItem() { Title = "Get Socks" };
db.ListItems.Add(socks);
Here is the actual query:
var queryresults = from item in db.ListItems
orderby item.Title
select item;
But the foreach loop doesn't print out anything:
WriteLine("Printing out the list:");
foreach (var item in queryresults)
{
WriteLine("Item's name:");
WriteLine(item.Title);
}
The rest:
}
WriteLine("All done.");
Console.Read();
}
}
}
I've tried to simplify as much as possible, but I cannot seem to get the results to show up. What is my mistake here?
Before the query try to save changes.
db.SaveChanges();

delete a node or triple using dotenetrdf librery?

I have an n3 file formate and i want to delete a node or triple from it how can i do it? should i use sparql query?please help me
i want to have an n3 file and want to delete a node from it.
i pass a graph that use in my parent form to this delete form and want to work with this graph that i create from an n3 file i mean i read this n3 file and convert it to a graph and send it to this form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VDS.RDF;
using VDS.RDF.Parsing;
using VDS.RDF.Query;
using System.IO;
using System.Windows;
using System.Runtime.InteropServices;
using VDS.RDF.Writing;
namespace WindowsFormsApplication2
{
public partial class delete : Form
{
Graph gra = new Graph();
public delete(Graph initialValue)
{
InitializeComponent();
ValueFromParent = initialValue;
}
private void delete_Load(object sender, EventArgs e)
{
}
public Graph ValueFromParent
{
set
{
this.gra = value;
}
}
}
}
From the documentation on Working with Graphs please see the section titled Asserting and Retracting triples which makes mention of the Assert() and Retract() methods which can be used to do what you've asked.
For example to delete a specific Triple:
//Assuming you already have the triple to delete in a variable t
g.Retract(t);
Or perhaps more usefully deleting all Triples that match a specific Node:
g.Retract(g.GetTriplesWithSubject(g.CreateUriNode(new Uri("http://example.org"))));
If you aren't sure whether a specific Node exists you can do something like the following:
INode n = g.GetUriNode(new Uri("http://example.org"));
//If n is null then the specified Node does not exist in the Graph
if (n != null)
{
g.Retract(g.GetTriplesWithSubject(n));
}
Note that you can't directly delete a Node from the Graph other than by removing all Triples that have it in the Subject/Object position. Also note that this does not remove it from the collection provided by the Nodes property of the Graph currently.
Yes you can also do this via SPARQL but for just removing a few triples that is very much overkill unless you need to remove triples based on some complex criteria which is not easily expressed directly using API selection and retraction methods.

Categories

Resources