What are the capabilities of .NET in AutoCad - autocad

Can anyone describe what you can create in C # in Autocad?
I would like to improve the work in the design office, but I do not know what my options are.
Can I create new objects?
Overlays forming an aomomatically drawing based on the given data
other
On the net I found only two blogs with posts from a few years earlier. There is nothing new.
Can anyone recommend any interesting articles, guides?
Any help will be helpful to get started. I know there is documentation but I will need some explanation step by step how everything works.

What you mentioned is possible. The API basics are the same since version 2007 (with incremental updated since and a couple binary breaks, but the code remains similar). For a new development, use the oldest version you plan to support (the last binary break release was 2013)
Visit the AutoCAD DevCenter and check:
Wizard for Visual Studio
Developer Guide
Training material
Webinars (Sessions 1-8)

You can definitely create new objects with the AutoCAD .Net API, below is an example I wrote a while ago, that creates a MLeader.
The .Net API is a managed wrapper around the C++ ObjectARX API, so it covers most of what the C++ API is capable of. The one thing that it cannot do is to derive custom classes from native ones, for Example AcDbLine cannot be extended through .Net. To achieve that you need to use the C++ API and can write a custom .Net wrapper in C++/CLI to expose it to .Net, then you will be able to instantiate your custom classes from .Net similarly to the built-in ones.
Modifying the behaviour of built-in entities can however be achieved directly in .Net by using overrules.
If your plugin is supposed to work only on Windows, then .Net is a more convenient choice than C++ and more flexible to implement UI's.
[CommandMethod("netTextMLeader")]
public static void netTextMLeader() {
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction Tx = db.TransactionManager.StartTransaction()) {
BlockTable table = Tx.GetObject(
db.BlockTableId,
OpenMode.ForRead) as BlockTable;
BlockTableRecord model = Tx.GetObject(
table[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
MLeader leader = new MLeader();
leader.SetDatabaseDefaults();
leader.ContentType = ContentType.MTextContent;
MText mText = new MText();
mText.SetDatabaseDefaults();
mText.Width = 100;
mText.Height = 50;
mText.SetContentsRtf("MLeader");
mText.Location = new Point3d(4, 2, 0);
leader.MText = mText;
int idx = leader.AddLeaderLine(new Point3d(1, 1, 0));
leader.AddFirstVertex(idx, new Point3d(0, 0, 0));
model.AppendEntity(leader);
Tx.AddNewlyCreatedDBObject(leader, true);
Tx.Commit();
}
}

With .Net can you create a new Object?
The answer is No. You need to use ObjectArx for that. However, with .Net you can modify how an object looks like. For example you can modify a line to look like an arrow. Not only how it looks but also how it behaves. So there is enough flexibility in .Net that is enough to compensate for the need to create new objects. Basically with .Net you have the power of windows and autocad.
A good resource of .Net samples is through the interface by Kean Walmsley. Try to go through this blog and you will learn more about .Net capabilities in AutoCAD than what I would ever be able to describe.

Related

Convert fhir between XML and Json

Is there a way to convert a fhir bundle from json to xml by means that is independent of the FHIR version used?
I think the .net fhir api by firely can do it, but any given version of the api seems to be specific to a certain release of FHIR.
The problem is that a FHIR Bundle (or any resource) implicitly always has a version. The rationale is that each FHIR version has (or can have) a different underlying data model.
It is possible though, using the .NET FHIR API (specifically package https://www.nuget.org/packages/Hl7.Fhir.Serialization) to do the conversion with minimal version differences.
The following code does the conversion using the version-independent ISourceNode (http://docs.simplifier.net/fhirnetapi/parsing/isourcenode.html)
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Serialization;
var xml = "<Patient xmlns=\"http://hl7.org/fhir\"><identifier><use value=\"official\" /></identifier></Patient>";
var patientNode = FhirXmlNode.Parse(xml);
var typedElement = patientNode.ToTypedElement();
var json = typedElement.ToJson();
The above code has one problem though, as VS will tell you. Using ToTypedElement() without parameters is dangerous because ignoring the version is. It will work in many cases though and if it is good enough for you that may be the way to go.
A safer solution is to use the same code, but to additionally use a so-called IStructureDefinitionSummaryProvider (apologies for the naming ;) to provide the API with specific version information. Implementations for this interface can be found in version-specific API libraries, e.g. https://www.nuget.org/packages/Hl7.Fhir.R4.
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Specification;
var xml = "<Patient xmlns=\"http://hl7.org/fhir\"><identifier><use value=\"official\" /></identifier></Patient>";
var patientNode = FhirXmlNode.Parse(xml);
var summaryProvider = new PocoStructureDefinitionSummaryProvider();
var typedElement = patientNode.ToTypedElement(summaryProvider);
var json = typedElement.ToJson();
You may be able to inject these PocoStructureDefinitionSummaryProviders based on some property of the input you are reading from. That is how we do it in the Vonk FHIR server for instance.
The FHIR java validator can do this for any version. That might be suitable depending on what you need to use it

How to access View Template Properties for Revit and compare them in Real Time?

I am trying to list the view template’s properties so we can compare them with another old template.
For example what model elements are hidden or have overrides in a given template or which Revit links have been hidden or overridden in a given template.
View Template
(https://www.google.com/search?q=view+template+revit&rlz=1C1GGRV_enUS770US770&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjLndrd2cTbAhVESq0KHX1cAPwQ_AUICygC&biw=1536&bih=824#imgrc=Q0v-pV7Nxl4kfM:)
I’m looking to devise a View Template Compare tool and access to the owner and creator of them.
public void ApplyViewTemplateToActiveView()
{
Document doc = this.ActiveUIDocument.Document;
View viewTemplate = (from v in new FilteredElementCollector(doc)
.OfClass(typeof(View))
.Cast<View>()
where v.IsTemplate == true && v.Name == "MyViewTemplate"
select v)
.First();
using (Transaction t = new Transaction(doc,"Set View Template"))
{
t.Start();
doc.ActiveView.ViewTemplateId = viewTemplate.Id;
t.Commit();
}
}
With Revit API you can access with:
GetTemplateParameterIds Method / ViewTemplateId Property
The Revit API exposes almost all the ViewTemplate properties.
For instance this method returns all the Visibility/Graphic Overrides for a specific category:
https://apidocs.co/apps/revit/2019/ed267b82-56be-6e3b-0c6d-4de7df1ed312.htm
The only thing I couldn't get for a ViewTemplate are the "includes", but all the rest seems to be there.
Update:
The list or properties "not included" can be retrieved with GetNonControlledTemplateParameterIds().
Yes, and no.
Yes, I guess you can use Forge Model Derivative API to export RVT file and then build a dashboard around the View Templates data. That's assuming that View Templates data actually gets exported when the model is translated. That data is not attached to any geometry so I would not be surprised if it was skipped. The question here is why? This is like renting a 16-wheel truck to move a duffel bag across the street.
No, if your intention is to directly interact with the RVT model. Forge can view it, but to push anything back or request changes to the model, is not available yet. Then again, I am not even sure that the view template data is available via model derivative exports.
This brings me another alternative. Why not just collect the data using Revit API, the standard way and then push it out to a Database and build on top of that? There is no reason to employ Forge for any of that.
Thanks Jeremy, I had dig into your amazing website and also some solution that Konrad post in the Dynamo Forum about this. In Revit seems pretty achievable, you filter the View that is View Template and then extracts these properties, is it correct?.
I am wondering if someone can point me in the right direction with Forge.
Some amazing guys are developing a BQL https://www.retriever.works/.
BQL(Building Query Language) is a query language for buildings, similar to how SQL is a query language for databases. It is fast and flexible. BQL helps improve efficiency for QA/QC (quality assurance and quality control), and building data extraction without leaving Revit. I am also trying these and I would like to understand if there are some works where I could start with Forge next week about this.

How to retrieve data from SSAS Cube using EDMX?

I was given a cube with all relevant information. Now, I want to query cube and get the data through .net EDMX framework.
Could anyone help me out from where I should start on this? I am really confused and have no idea how to use MDX with edmx.
Is it possible to get the data from Cubes without using MDX using EDMX with LINQ?
It's not possible currently, there is a company who do a version of LinqToMdx, I think they've posted on here before, I don't think they go via the EDMX route exactly.
Standard method in .Net is ADOMD.Net http://msdn.microsoft.com/en-us/library/ms123477.aspx
A nice way of getting data is via the CellSet class, as it contains cells of both the native value and the formatted string for measures:
CellSet adomdCellSet;
using (var adomdConnection = new AdomdConnection())
{
adomdConnection.ConnectionString = "YourConnectionString";
adomdConnection.Open();
var adomdCommand = adomdConnection.CreateCommand();
adomdCommand.CommandText = "YourMDXQuery";
adomdCellSet = adomdCommand.ExecuteCellSet();
}
return adomdCellSet;
Edit: Found the site of the guys who wrote a provider - I can't vouch for them as I've never used it, but it looks interesting http://www.agiledesignllc.com/Products.htm

Reliable and efficient way to handle Azure Table Batch updates

I have an IEnumerable that I'd like to add to Azure Table in the most efficient way possible. Since every batch write has to be directed to the same PartitionKey, with a limit of 100 rows per write...
Does anyone want to take a crack at implementing this the "right" way as referenced in the TODO section? I'm not sure why MSFT didn't finish the task here...
Also I'm not sure if error handling will complicate this, or the correct way to implement it. Here is the code from the Microsoft Patterns and Practices team for Windows Azure "Tailspin Toys" demo
public void Add(IEnumerable<T> objs)
{
// todo: Optimize: The Add method that takes an IEnumerable parameter should check the number of items in the batch and the size of the payload before calling the SaveChanges method with the SaveChangesOptions.Batch option. For more information about batches and Windows Azure table storage, see the section, "Transactions in aExpense," in Chapter 5, "Phase 2: Automating Deployment and Using Windows Azure Storage," of the book, Windows Azure Architecture Guide, Part 1: Moving Applications to the Cloud, available at http://msdn.microsoft.com/en-us/library/ff728592.aspx.
TableServiceContext context = this.CreateContext();
foreach (var obj in objs)
{
context.AddObject(this.tableName, obj);
}
var saveChangesOptions = SaveChangesOptions.None;
if (objs.Distinct(new PartitionKeyComparer()).Count() == 1)
{
saveChangesOptions = SaveChangesOptions.Batch;
}
context.SaveChanges(saveChangesOptions);
}
private class PartitionKeyComparer : IEqualityComparer<TableServiceEntity>
{
public bool Equals(TableServiceEntity x, TableServiceEntity y)
{
return string.Compare(x.PartitionKey, y.PartitionKey, true, System.Globalization.CultureInfo.InvariantCulture) == 0;
}
public int GetHashCode(TableServiceEntity obj)
{
return obj.PartitionKey.GetHashCode();
}
}
Well, we (the patterns & practices team) just optimized for showing other things we considered useful. The code above is not really a "general purpose library", but rather a specific method for the sample that uses it.
At that moment we thought that adding that extra error handling would not add much, and we diceided to keep it simple, but....we might have been wrong.
Anyway, if you follow the link in the //TODO:, you will find another section of a previous guide we wrote that talks a little bit more on error handling in "complex" storage transactions (not in the "ACID" form though as transactions "ala DTC" are not supported in Windows Azure Storage).
Link is this: http://msdn.microsoft.com/en-us/library/ff803365.aspx
The limitations are listed in more detail there:
Only one instance of the entity should be present in the batch
Max 100 entities or 4 MB payload
Same PartitionKey (which is being handled in the code: notice that "batch" is only specified if there's a single Partition key)
etc.
Adding some extra error handling should not overcomplicate things too much, but depends on the type of app you are building on top of this and your preference to handle this higher or lower in your app stack. In our example, the app would never expect > 100 entities anyway, so it would simply bubble the exception up if that situation happens (because it should be truly exceptional). Same with the total size. The use cases implemented in the app make it impossible to have the same entity in the same collection, so again, that should never happen (and if it happens, it wouls simply throw)
All "entity group transactions" limitations are documented here: http://msdn.microsoft.com/en-us/library/dd894038.aspx
Let us know how it goes! I'm also interested to know if other pieces of the guide were useful for you.

Programmatically list WMI classes and their properties

Is there any known way of listing the WMI classes and their properties available for a particular system? Im interested in a vbscript approach, but please suggest anything really :)
P.S. Great site.
I believe this is what you want.
WMI Code Creator
A part of this nifty utility allows you to browse namespaces/classes/properties on the local and remote PCs, not to mention generating WMI code in VBScript/C#/VB on the fly. Very useful.
Also, the source code used to create the utility is included in the download, which could provide a reference if you wanted to create your own browser like interface.
This MSDN page walks through enumerating the available classes: How to: List the Classes in a WMI Namespace
for retrieving properties from a class:
ManagementPath l_Path = new ManagementPath(l_className);
ManagementClass l_Class = new ManagementClass(myScope, l_ManagementPath, null);
foreach (PropertyData l_PropertyData in l_Class.Properties)
{
string l_type = l_PropertyData.Type.ToString());
int l_length = Convert.ToInt32(l_PropertyData.Qualifiers["maxlen"].Value);
}

Resources