Hi all,
I'm trying to use HLR api to get all the line from block but it's cannot find any line.
Here is the code:
public static void HLRTest()
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World!\n");
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityResult res = Application.DocumentManager.MdiActiveDocument.Editor.GetNestedEntity("\nSelect object: ");
if (res.Status != PromptStatus.OK)
return;
AcMgHlrCollector collector = new AcMgHlrCollector
{
DeleteState = true
};
collector.addEntity(res.ObjectId);
// Get current viewport settings
Point3d tmpt = (Point3d)Application.GetSystemVariable("viewdir"); //new Vector3d(1,1,1);
//transform UCS to WCS;
Vector3d viewdir = tmpt.TransformBy(ed.CurrentUserCoordinateSystem).GetAsVector();
Point3d target = (Point3d)Application.GetSystemVariable("target"); //new Point3d(0, 0, 0);
//transform UCS to WCS
target = target.TransformBy(ed.CurrentUserCoordinateSystem);
// Process hidden line removal
AcMgHlrEngine hlr = new AcMgHlrEngine(
target, viewdir,
(int)(HlrControl.Entity | HlrControl.Block | HlrControl.Subentity | HlrControl.ShowAll | HlrControl.Progress) //Madhukar, progress param needed
);
hlr.run(collector);
//- Assign color to the resulting entities
//- red for visible edges
//- blue for non-visible edges
//- yellow for internal edges
Database db = Application.DocumentManager.MdiActiveDocument.Database;
Transaction tr = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction();
try
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
int n = collector.OutputDataLength;
for (int i = 0; i < n; i++)
{
AcMgHlrData p = collector.OutputData(i);
Entity pEnt = p.ResultEntity;
Autodesk.AutoCAD.HLR.Visibility vis = p.EntityVisibility;
if (vis == Autodesk.AutoCAD.HLR.Visibility.Visible)
{
pEnt.ColorIndex = 1; //----- Red
ms.AppendEntity(pEnt);
tr.AddNewlyCreatedDBObject(pEnt, true);
}
else if (vis == Autodesk.AutoCAD.HLR.Visibility.InternallyHidden)
{
if (p.HlrVisibility == Autodesk.AutoCAD.HLR.Visibility.Visible)
pEnt.ColorIndex = 2; //----- Yellow
else
pEnt.ColorIndex = 3; //----- Green
}
else
{
pEnt.ColorIndex = 5; //----- Blue
}
}
tr.Commit();
}
catch (System.Exception ex)
{
tr.Abort();
}
finally
{
tr.Dispose();
}
}
At the line
collector.OutputDataLength
It give me zero line
The item i select is just a normal block
The more weird thing is it will work only if I open a drawing which has Advance Steel profile in there.
It's very confuse and I dont know the relation, if anyone know what happen please help, really appreciate.
Thank you.
Solved! Go to Solution.
Solved by R.Gerritsen4967. Go to Solution.
Solved by quan_hm. Go to Solution.
What happens when you select a solid3D or a surface when you run the command?
It's been a long time since I played around with the HLR api, but does the api accept other objects than solids and surfaces?
Hi @R.Gerritsen4967 ,
I did try with solids, surface but still not work.
I found the solution, I need to load AsdkHlrApi24.dbx file manual, somehow when I open a advance steel drawing it will automatic load otherwise I have to load AsdkHlrApi24.dbx then it will work.
Can't find what you're looking for? Ask the community or share your knowledge.