Creating hatch on different layered geometry

Creating hatch on different layered geometry

SaddamShaikh77
Advocate Advocate
1,083 Views
11 Replies
Message 1 of 12

Creating hatch on different layered geometry

SaddamShaikh77
Advocate
Advocate

Hello forum,
I want to create hatch for the following images. Manually I can create hatch as expected as seen in the following image.

SaddamShaikh77_0-1607495743251.png

I want to achieve same using api. I have implemented code as below

 

public void FilterSelectionSet1()
{
Document acDoc = aCAD_App.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor acDocEd = aCAD_App.DocumentManager.MdiActiveDocument.Editor;
Polyline rect = new Polyline();

TypedValue[] acTypValAr = new TypedValue[] { new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE") };

PromptSelectionResult acSSPrompt;
acSSPrompt = acDocEd.SelectAll();
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

foreach (SelectedObject acSSObj in acSSet)
{
Entity acEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;
if (acEnt != null)
{
string entLayer = acEnt.Layer;
if (entLayer == "Revit-Profile Location")
{
rect = acEnt as Polyline;
}
}
}

int verticesCount = rect.NumberOfVertices;

for (int i = 0; i < verticesCount; i++)
{
Point2d pt = rect.GetPoint2dAt(i);
}

Hatch acHatch = new Hatch();
acBlkTblRec.AppendEntity(acHatch);
acTrans.AddNewlyCreatedDBObject(acHatch, true);

ObjectIdCollection objectIdCollection = new ObjectIdCollection();
objectIdCollection.Add(rect.ObjectId);

acHatch.SetDatabaseDefaults();
acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
acHatch.Associative = true;
acHatch.AppendLoop(HatchLoopTypes.Outermost, objectIdCollection);
acHatch.PatternScale = 0.5;
acHatch.HatchStyle = HatchStyle.Outer; // tried HatchStyle.normal and ignore also ignore throws exception
acHatch.EvaluateHatch(true);
}
else
{
aCAD_App.ShowAlertDialog("Number of objects selected: 0");
}
acTrans.Commit();
}
}

But I am getting result as,

SaddamShaikh77_1-1607496006015.png

Please note that, inner geometry that  is triangular shaped is on a different layer called "Pdf_Geometry" and outer rectangle is on other layer "Pdf_geom location".
Please help me to achieve the output I want.

Thank you in advance.

 

 

0 Likes
1,084 Views
11 Replies
Replies (11)
Message 2 of 12

SeeMSixty7
Advisor
Advisor

You need to add the outer triangle to the objectIdCollection. Then It will give you the hatch you want.

 

Good luck

0 Likes
Message 3 of 12

SaddamShaikh77
Advocate
Advocate

Thank you for reply.
Calculating that outer triangle is the task here! To achieve that I have used concept of hatching.
I have manually created hatch and in later part I am getting the outer triangle profile.
The task here is to automate hatch that I did manually as shown in first image above.
Please guide me if any other way is available?
Can I use Editor.Command("HATCH",point2D) or Document.SendStringToExecute("HATCH \n", true, false, true);
Or any other way that could be used to achieve this?

 

0 Likes
Message 4 of 12

SeeMSixty7
Advisor
Advisor

Do you have either of the triangles when you go to perform the hatch? You want to have the outer rectangle and the Outer triangle before you perform the hatch. Then you simply use both to create the hatch. If you can calculate the triangle from the rectangle data, then go ahead and get that done then do the hatch. Are you trying to use the Hatch command to get information about the Triangle or something?

0 Likes
Message 5 of 12

SaddamShaikh77
Advocate
Advocate

Yes, I am using the hatch command to retrieve the outer triangle from the pdf page which is imported over the dwg drawing template.
I have that outer rectangle and creating hatch for the same now. I don't have the outer triangle. My aim is to get that outer triangle only. As shwon below is the original picture from which I want to retrieve the outer bound of the triangle.

If this hacth concept works I need to extract data from all the colored boxes in the drawing. 

SaddamShaikh77_0-1607535822233.png

I am attaching the sample dwg from which you will get a clear idea. Please let me know if you have some better idea to achieve this but I found hatching to be the easier and quickest way.

Thank you.

 

0 Likes
Message 6 of 12

SeeMSixty7
Advisor
Advisor

Your drawing is just a pline box. I assume the PDF was a reference and not included. Your picture samples are so small I can't actually read anything on them.

 

ok, so it sounds like you are using a PDF background and generating the PLINE boundary for the hatch. Is the hatch the desired end result for area or something? If the Triangle data is in the pdf already, then can you not convert to ACAD dwg entities and then generate the triangles from the data you can get from the new entities based on relative locations?

0 Likes
Message 7 of 12

SaddamShaikh77
Advocate
Advocate

Yes, I am using pdf background.
I have drawing template in coloured lines and I am importing pdf onto it.
Triangled entities are in pdf under the specific layer but retrieving them is the real challenge for me.
Triangles, rectangles, polylines might be entities from which I have to get their outer curves/boundary.

If by any means I can get triangles or other entities then I need to go with creating hatch.

But till now I found hatching is the quicker and easier way.

Using manual hatch, I am getting desired output as below.

SaddamShaikh77_0-1607573901051.png

 

0 Likes
Message 8 of 12

SaddamShaikh77
Advocate
Advocate

Steps I am following:

1. Import dwg template

SaddamShaikh77_0-1607574121390.png

2. Import pdf on template with geometry and other details

SaddamShaikh77_1-1607574941506.png

3. Apply manual hatch and get result

SaddamShaikh77_2-1607575180169.png

4. Get result as

SaddamShaikh77_3-1607575266165.png

Now I need to automate step 3 of manual hatching

0 Likes
Message 9 of 12

SeeMSixty7
Advisor
Advisor

If there is a consistent layer set for the entities as they come over into ACAD via PDF Import, you may be able to get what you are looking for. Attached a DWG file with the PDF already imported and I'll see if I can help point you in a direction that works.

 

Good luck,

0 Likes
Message 10 of 12

SaddamShaikh77
Advocate
Advocate

Please find the attached dwg and let me know any possible way.

Thank you.

0 Likes
Message 11 of 12

SeeMSixty7
Advisor
Advisor

Ok, Looking at this, you may be able to get away with a bit of a hack.

Prep the drawing

import the PDF

Erase all text, mtext or just freeze the layer.

Erase all SPLINE Entities (little circles around your drawing)

Calculate two corners of the outside rectangle (Upper Left and Lower Right)

(get the Angle of those two points from UL to LR)

Calculate a point at 0.01 at that angle to be inside the rectangle

Use the BOUNDARY command and provide that point.

The result will be several closed plines. The Last two are what you are looking for. The Last Entity is the outer rectangle and the next to last entity is the triangleish shape you want. You can get the last ent, get the data from it, then delete it and you will have a new last entity which would be the second to last. Or you could take a snap shot of entities before you run BOUNDARY and then make a selection set of those ent post BOUNDARY and then step through to get the Last two ents.

 

You may need to verify that BOUNDARY Always works from inside out to provide the same results.

 

Hope that helps.

 

Using BPOLY (BOUNDARY) you can creat

0 Likes
Message 12 of 12

SaddamShaikh77
Advocate
Advocate

Thank you for the guidelines.

I will try this but I need to fight with finding entities and I don't know much about boundary or region creation.

I can get UL/LR points but angle and boundary need to check. Will search for it.
Cant' we creat hatch using ed.command("HATCH",Pt); (Point inside the outer rectagle) or

doc.SendStringToExecute("HATCH",true,false,false); like we do for other commands.

I am asking this because I also want some other parameter details like Ply,Qty text mentioned in the pdf page.

If by any means Hatch works for me, that will be easier for me to get my results.

Please let me know if you could think of any different way to apply hacth. Meanwhile, I will explore on boundary command.

Thank you.

 

 

 

0 Likes