<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: AcGiVisualStyle : Custom entity. in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8965679#M5231</link>
    <description>&lt;P&gt;The code I have provided is being called from the subWorldDraw(….) call of the containing AcDbEntity derived class. This drawing context is that of the world draw not a viewport.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Aug 2019 13:00:10 GMT</pubDate>
    <dc:creator>tech</dc:creator>
    <dc:date>2019-08-14T13:00:10Z</dc:date>
    <item>
      <title>AcGiVisualStyle : Custom entity.</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8936465#M5229</link>
      <description>&lt;P&gt;I am trying to render my entity differently depending on the current visual style selected. I am trying to get the current visual style for the subEntityTraits of the drawing context but the call is returning a null object id. Any ideas?&lt;/P&gt;&lt;PRE&gt;Adesk::Boolean TPG_Drawable::Draw(AcArray&amp;lt;TPG_Entity*&amp;gt;&amp;amp; ents, AcGiWorldDraw* dc, int options, bool cacheExtents)
{
	auto &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;styleId&lt;/STRONG&gt; &lt;/FONT&gt;= dc-&amp;gt;subEntityTraits().visualStyle();
	AcRxObject* rxObj = nullptr;

	if (acdbOpenObject(rxObj, &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;styleId&lt;/STRONG&gt;&lt;/FONT&gt;, AcDb::kForRead) == Acad::eOk)
	{
		auto style = static_cast&amp;lt;AcGiVisualStyle*&amp;gt;(rxObj);
		switch (style-&amp;gt;type())
		{
		case AcGiVisualStyle::Type::k2DWireframe:
			break;
		case AcGiVisualStyle::Type::k3DWireframe:
		{
			auto rep = GetRepresentation3D();
			rep-&amp;gt;worldDraw(dc);
		}
			return Adesk::kTrue;
		case AcGiVisualStyle::Type::kRealistic:
			break;
		}
	}
        return Adesk::kTrue;
}&lt;/PRE&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 14:48:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8936465#M5229</guid>
      <dc:creator>tech</dc:creator>
      <dc:date>2019-07-29T14:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: AcGiVisualStyle : Custom entity.</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8948377#M5230</link>
      <description>&lt;P&gt;The visual style is a property of the viewport - either of an &lt;FONT face="courier new,courier"&gt;AcDbViewport&lt;/FONT&gt; entity in a layout if tilemode=0 or of an &lt;FONT face="courier new,courier"&gt;AcDbViewportTableRecord&lt;/FONT&gt; if tilemode=1. So I would expect to find a style ID&amp;lt;&amp;gt;null only via the &lt;FONT face="courier new,courier"&gt;AcGiViewportDraw&lt;/FONT&gt; that is provided in &lt;FONT face="courier new,courier"&gt;subViewportDraw()&lt;/FONT&gt; and not in &lt;FONT face="courier new,courier"&gt;AcGiWorldDraw&lt;/FONT&gt;, which contains the properties common to all views.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 12:35:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8948377#M5230</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2019-08-05T12:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: AcGiVisualStyle : Custom entity.</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8965679#M5231</link>
      <description>&lt;P&gt;The code I have provided is being called from the subWorldDraw(….) call of the containing AcDbEntity derived class. This drawing context is that of the world draw not a viewport.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 13:00:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8965679#M5231</guid>
      <dc:creator>tech</dc:creator>
      <dc:date>2019-08-14T13:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: AcGiVisualStyle : Custom entity.</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8967254#M5232</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3258563"&gt;@tech&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The code I have provided is being called from the subWorldDraw(….) call of the containing AcDbEntity derived class. This drawing context is that of the world draw not a viewport.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;...and the world draw context does only contain information that is common to all views/viewports.&lt;BR /&gt;But the shademode is viewport specific. So you can't react to the shademode within world draw.&lt;/P&gt;
&lt;P&gt;You have to move your code to viewport draw to do this.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 07:12:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8967254#M5232</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2019-08-15T07:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: AcGiVisualStyle : Custom entity.</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8997998#M5233</link>
      <description>&lt;P&gt;I have made the following changes to force a call to subViewportDraw but the visual style id returned from the sub entity traits is still AcDbObjectId::kNull.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/// &amp;lt;summary&amp;gt; Overridden to call the custom Draw method. &amp;lt;/summary&amp;gt;
Adesk::Boolean TPG_Entity::subWorldDraw(AcGiWorldDraw* dc)
{
	if (dc-&amp;gt;regenAbort()) 
		return Adesk::kTrue; // Stop drawing.
	

	return Adesk::kFalse; // Force call to subViewportDraw(...)
}

/// &amp;lt;summary&amp;gt; &amp;lt;/summary&amp;gt;
void TPG_Entity::subViewportDraw(AcGiViewportDraw* dc)
{
	auto visualStyleId = dc-&amp;gt;subEntityTraits().visualStyle();
	if (visualStyleId != AcDbObjectId::kNull)
	{
		AcGiVisualStyle* style = nullptr;
		if (acdbOpenObject((AcRxObject*&amp;amp;)style, visualStyleId, AcDb::kForRead) == Acad::eOk)
		{
			if (style-&amp;gt;type() != AcGiVisualStyle::Type::k2DWireframe)
				acutPrintf(L"3D Mode");
		}
	}
	
	Draw(AcArray&amp;lt;TPG_Entity*&amp;gt;(), dc);
}&lt;/PRE&gt;&lt;P&gt;Any ideas from anyone on how to get the current visual style selected by the user?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2019 15:36:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/8997998#M5233</guid>
      <dc:creator>tech</dc:creator>
      <dc:date>2019-08-30T15:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: AcGiVisualStyle : Custom entity.</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/9001064#M5234</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Ac&lt;U&gt;&lt;STRONG&gt;Gi&lt;/STRONG&gt;&lt;/U&gt;VisualStyle &lt;/FONT&gt;is not derived from &lt;FONT face="courier new,courier"&gt;AcDbObject&lt;/FONT&gt;. So &lt;FONT face="courier new,courier"&gt;acdbOpenObject()&lt;/FONT&gt; will do an illegal cast!&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;AcDbObjectId visualStyleId&lt;/FONT&gt; is the objectId of an &lt;FONT face="courier new,courier"&gt;Ac&lt;U&gt;&lt;STRONG&gt;Db&lt;/STRONG&gt;&lt;/U&gt;VisualStyle&lt;/FONT&gt; object located in the ACAD_VISUALSTYLE dictionary. Just replace &lt;FONT face="courier new,courier"&gt;Ac&lt;U&gt;&lt;STRONG&gt;Gi&lt;/STRONG&gt;&lt;/U&gt;VisualStyle&lt;/FONT&gt; in your code by &lt;FONT face="courier new,courier"&gt;Ac&lt;U&gt;&lt;STRONG&gt;Db&lt;/STRONG&gt;&lt;/U&gt;VisualStyle&lt;/FONT&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are in not tilemode, you can get the visual style ID from the &lt;FONT face="courier new,courier"&gt;AcDbViewport&lt;/FONT&gt; like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;void TPG_Entity::subViewportDraw(AcGiViewportDraw* dc) 
{
	AcDbObjectId idVP = dc-&amp;gt;viewportObjectId(); // null if TILEMODE=1
	AcDbObjectId visualStyleId;
	AcDbViewport *vp;
	if ( (es=acdbOpenObject(vp, idVP, AcDb::kForRead)) == Acad::eOk )
	{
		visualStyleId = vp-&amp;gt;visualStyle();
		vp-&amp;gt;close();
	}
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 11:49:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/9001064#M5234</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2019-09-02T11:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: AcGiVisualStyle : Custom entity.</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/9003842#M5235</link>
      <description>&lt;P&gt;Thanks, that works, but what if tilemode = 1? Any ideas. I set TILEMODE = 0 and the code you provided works, the only problem is that TILEMODE = 1 by default I think.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 17:23:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/9003842#M5235</guid>
      <dc:creator>tech</dc:creator>
      <dc:date>2019-09-03T17:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: AcGiVisualStyle : Custom entity.</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/9003951#M5236</link>
      <description>&lt;P&gt;The following code does what I want. The hint was from TBrammer and the suggestion of viewports.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/// &amp;lt;summary&amp;gt; &amp;lt;/summary&amp;gt;
void TPG_Entity::subViewportDraw(AcGiViewportDraw* dc)
{
	AcDbDatabase*db =
		acdbHostApplicationServices()-&amp;gt;workingDatabase();

	AcDbViewportTable *vpt = nullptr;
	if (db-&amp;gt;getViewportTable(vpt, AcDb::kForRead) == Acad::eOk)
	{
		AcDbViewportTableRecord *vp = nullptr;
		if (vpt-&amp;gt;getAt(L"*Active", vp, AcDb::kForRead) == Acad::eOk)
		{
			auto vsid = vp-&amp;gt;visualStyle();
			AcDbVisualStyle* style = nullptr;
			if (acdbOpenObject(style, vsid, AcDb::kForRead) == Acad::eOk)
			{
				auto type = style-&amp;gt;type();
				if (type == AcGiVisualStyle::k2DWireframe)
					acutPrintf(L"2D");
				else
					acutPrintf(L"3D");
				style-&amp;gt;close();
			}
			vp-&amp;gt;close();
		}
		vpt-&amp;gt;close();
	}

	CommonDraw(AcArray&amp;lt;TPG_Entity*&amp;gt;(), dc);
}&lt;/PRE&gt;&lt;P&gt;Although I am able to get the current visual style, I don't believe this is the best solution to this problem. Surely, this information should be accessible through the drawing context or sub-entity traits?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 18:13:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acgivisualstyle-custom-entity/m-p/9003951#M5236</guid>
      <dc:creator>tech</dc:creator>
      <dc:date>2019-09-03T18:13:25Z</dc:date>
    </item>
  </channel>
</rss>

