Draw line with lineweigth by AcEdInputPointMonitor class

Draw line with lineweigth by AcEdInputPointMonitor class

majklha
Advocate Advocate
296 Views
1 Reply
Message 1 of 2

Draw line with lineweigth by AcEdInputPointMonitor class

majklha
Advocate
Advocate

I have a class CMajUsekMonitor derived from AcEdInputPointMonitor

In method ...monitorInputPoint(const AcEdInputPoint &input, AcEdInputPointMonitorResult &output) I need to draw temporay line, and for amhasizing I need it draw with bigger thickness.

 

I try this, but it doesnot work (in drawing I have LWDISPLAY on):

How force Autocad to draw thick line.

 

Acad::ErrorStatus CMajUsekMonitor::monitorInputPoint(const AcEdInputPoint &input, AcEdInputPointMonitorResult &output)
{
	if (input.pointComputed())
	{
		getNearest(input.computedPoint());
		auto &traits = input.drawContext()->subEntityTraits();

		traits.setColor(2);
		traits.setLineWeight(AcDb::kLnWt140);
		traits.setSelectionMarker(2);

		AcGePoint3d pts[2] = { asPnt3d(m_itLom->bod), asPnt3d((m_itLom + 1)->bod) };
		input.drawContext()->geometry().polyline(2, pts);

		if (m_bInfo)
			acedGrText(-1, m_itLom->GetInfo(), 0);
	}
	return Acad::eOk;
}

 

0 Likes
Accepted solutions (1)
297 Views
1 Reply
Reply (1)
Message 2 of 2

daniel_cadext
Advisor
Advisor
Accepted solution

I could not get it to work either; I also tried just drawing a polyline in geo.draw()

You may be able to simulate it though, a wacky proof of concept using polygon

 

# C++ hint
# rt = ads_getvar(L"VIEWSIZE", &var);
# view->setHeight(var.resval.rreal);

# resbuf rbScreen;
# if (acedGetVar(_T("SCREENSIZE"), &rbScreen) == RTNORM)
# {
#     double pixelX = rbScreen.resval.rpoint[X];
#     double pixelY = rbScreen.resval.rpoint[Y];
#     if (pixelY != 0)
#     {
#         view->setWidth(var.resval.rreal * (pixelX / pixelY));
#     }
# }

# do this in mfc
display = wx.Display(0)
geometry = display.GetGeometry()
screen_res_y = float(geometry.Height)

class MyPointMonitor(Ed.InputPointMonitor):
    def __init__(self):
        Ed.InputPointMonitor.__init__(self)

    def simulatePolygon(self, a: Ge.Point3d, b: Ge.Point3d, pixel_width: float = 5):
        v = Ed.Core.getCurrentView()
        thickness = (v.height() / screen_res_y) * pixel_width
        vec: Ge.Vector3d = b - a
        if vec.length() < 1e-6:
            return []
        perp_vec = Ge.Vector3d(-vec.y, vec.x, 0).normal()
        offset = thickness / 2.0
        p1 = a + (perp_vec * offset)
        p2 = a - (perp_vec * offset)
        p3 = b - (perp_vec * offset)
        p4 = b + (perp_vec * offset)
        return [p1, p4, p3, p2, p1]

    def monitorInputPoint(self, input: Ed.InputPoint, output):
        try:
            ents = input.pickedEntities()
            if len(ents) == 0:
                return

            p = input.rawPoint()
            geo = input.drawContext().geometry()
            tr = input.drawContext().subEntityTraits()
            tr.setFillType(Gi.FillType.kAcGiFillAlways)

            tr.setColor(3)
            plypnts = self.simulatePolygon(
                p, p + (Ge.Point3d(0, 0, 0) - Ge.Point3d(100, 100, 0))
            )
            geo.polygon(plypnts)

            tr.setColor(1)
            plypnts = geo.polyline(
                [p, p + (Ge.Point3d(100, 100, 0) - Ge.Point3d(0, 0, 0))]
            )

        except Exception as err:
            print(err)

 

pymon.png

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx