.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HLR Cannot find lines

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
quan_hm
279 Views, 4 Replies

HLR Cannot find lines

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

quan_hm_0-1721625422521.png

The item i select is just a normal block

quan_hm_1-1721625460135.png

The more weird thing is it will work only if I open a drawing which has Advance Steel profile in there.

quan_hm_2-1721625593243.png

It's very confuse and I dont know the relation, if anyone know what happen please help, really appreciate. 

Thank you. 

 

Hoang Minh Quan - Piping design engineer
Autodesk Store for Python Catalog
4 REPLIES 4
Message 2 of 5
R.Gerritsen4967
in reply to: quan_hm

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?

Message 3 of 5
quan_hm
in reply to: quan_hm

Hi @R.Gerritsen4967 ,

I did try with solids, surface but still not work. 

 

Hoang Minh Quan - Piping design engineer
Autodesk Store for Python Catalog
Message 4 of 5
quan_hm
in reply to: quan_hm

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. 

Hoang Minh Quan - Piping design engineer
Autodesk Store for Python Catalog
Message 5 of 5
R.Gerritsen4967
in reply to: quan_hm

I was just going to link to this topic: click

The solution you found, was also posted in that topic.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report