DWG to RVT not converting all lines

DWG to RVT not converting all lines

luisdavid.mena
Enthusiast Enthusiast
1,023 Views
7 Replies
Message 1 of 8

DWG to RVT not converting all lines

luisdavid.mena
Enthusiast
Enthusiast

Hello.

I'm writing a macro which convert DWG (ImportInstance) into Revit Lines. It is working fine, but I'm frustrated because not all the lines are being converted, as you can see in the attached image, and I cannot find the reason why. I'd be grateful if someone could give me some advice regarding this issue.

I share my code in C# and the CAD file if it is useful.

Conversion_DWG.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The Code in the Macro:

 

 

//Get CAD's
var cads = new FilteredElementCollector(doc).OfClass(typeof(ImportInstance)).WhereElementIsNotElementType().WhereElementIsNotElementType();
ImportInstance imporInst = cads.FirstElement() as ImportInstance;
			
IList<Curve> lines = new List<Curve>();
IList<Curve> polylines = new List<Curve>();
IList<Curve> arcs = new List<Curve>();
IList<Curve> ellipses = new List<Curve>();
			
Options op = doc.Application.Create.NewGeometryOptions();
op.ComputeReferences = true;
op.IncludeNonVisibleObjects = true;
			
//Get Geometry
GeometryElement geoElem1 = imporInst.get_Geometry(op);
			
//Get Lines
if(geoElem1 != null)
{
	foreach(GeometryObject geoObj1 in geoElem1)
	{
		GeometryInstance geoInst = geoObj1 as GeometryInstance;
		if(geoInst != null)
		{
			GeometryElement geoElem2 = geoInst.GetInstanceGeometry() as GeometryElement;
			if(geoElem2 != null)
			{
				foreach(GeometryObject geoObj2 in geoElem2)
				{
					//Lines
					if(geoObj2 is Line)
						lines.Add(geoObj2 as Curve);
					//Polylines
					if(geoObj2 is PolyLine)
						polylines.Add(geoObj2 as Curve);
					//Arcs
					if(geoObj2 is Arc)
						arcs.Add(geoObj2 as Curve);
					//Ellipses
					if(geoObj2 is Ellipse)
						ellipses.Add(geoObj2 as Curve);
				}
			}
		}
	}
}
			
//Create Curves
using(Transaction curves = new Transaction(doc))
{
	curves.Start("Convierte DWG a RVT");
	//lines
	foreach(Curve c in lines)
	{
		if(c != null)
			doc.Create.NewDetailCurve(doc.ActiveView, c);
	}
	//polylines
	foreach(Curve c in polylines)
	{
		if(c != null)
			doc.Create.NewDetailCurve(doc.ActiveView, c);
	}
	//Arcos
	foreach(Curve c in arcs)
	{
		if(c != null)
			doc.Create.NewDetailCurve(doc.ActiveView, c);
	}
	//Ellipses
	foreach(Curve c in ellipses)
	{
		if(c != null)
			doc.Create.NewDetailCurve(doc.ActiveView, c);
	}
	curves.Commit();
}

 

 

 

0 Likes
Accepted solutions (1)
1,024 Views
7 Replies
Replies (7)
Message 2 of 8

jeremy_tammik
Alumni
Alumni

Yes, I have heard of such issues in the past. You may possibly be able to affect the behaviour by modifying your view settings. However, I am not an expert in this area, and neither are many others in the forum. Unfortunately, this is not the best place to ask such a question.

 

Please note that this discussion forum is dedicated to programming Revit using the Revit API. The Revit API basically just provides access to the underlying Revit product user interface functionality. I believe that it will help to solve your issue manually from an end user point of view first, before addressing the programming side of things.

 

You will probably have more success and address more knowledgeable people or that aspect of things in the non-API Revit product support discussion forums:

 

https://forums.autodesk.com/t5/revit-api-forum/this-forum-is-for-revit-api-programming-questions-not...

 

The people there are much better equipped to address this topic than us programming nerds.

 

I hope this clarifies.

 

Thank you for your cooperation and understanding.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 8

RPTHOMAS108
Mentor
Mentor
Accepted solution

Should review the geometry in RevitLookup to identify the missing parts i.e. what they are.

 

I can say however that PolyLines don't derive from Curve so if you try to cast a PolyLine to a Curve you'll end up with a bunch of nulls and then these will be skipped and not drawn in your subsequent code that checks for nulls.

 

 If these missing parts are PolyLines then you'll have to construct Lines by iterating the points of the PolyLine.

 

Code is a bit complicated since a list of curves is what you need at the end to be drawing so why split them into separate lists of Arcs, Lines, Ellipses etc.

 

Your problem will be the text unless you don't care about that aspect. Text in DWG imports are not exposed as geometry to the API. Would likely have to use the custom exporter framework for that (IExportContext2D).

0 Likes
Message 4 of 8

FrankHolidaytoiling
Advocate
Advocate

There is another object that is called Solid, I am finding in some Cad Files. It is like a flat cad section nonetheless and yet you have to iterate it's edges and maybe more as I don't understand it's architecture I will just say that they are another thing to deconstruct in order to rebuild as detail lines in a RFA    

Message 5 of 8

FrankHolidaytoiling
Advocate
Advocate

I have to Face-up to it that there is more, sorry. Probably just ignore my post I am a cad importing noob. 

0 Likes
Message 6 of 8

jeremy_tammik
Alumni
Alumni

Maybe taking a look at the ElementViewer SDK sample will help unravel this; it displays all edges for all elements and applies all the appropriate transformations to them:

 

RevitSdkSamples/SDK/Samples/Viewers/ElementViewer

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 7 of 8

luisdavid.mena
Enthusiast
Enthusiast

Thank you for your advice @jeremy_tammik . I really appreciate that. I posted in this forum because I'm working with the API, but it seems that I need first to study more the behaviour and properties of the elements from the Geometry and API perspective. I'm an architect, noob at programming but really interested in the capabilities of the Open Source in Revit, therefore I appreciate the advice fom the programming nerds in this forum 🙂

0 Likes
Message 8 of 8

luisdavid.mena
Enthusiast
Enthusiast

Thank you for your help @RPTHOMAS108 . I think it will take a little longer to get those Lines. I will take this issue as solved in order to close it and possibly open a new topic If I get stuck in the way.

0 Likes