How to get access to a layout's model space?

How to get access to a layout's model space?

syx_lemans
Enthusiast Enthusiast
2,059 Views
8 Replies
Message 1 of 9

How to get access to a layout's model space?

syx_lemans
Enthusiast
Enthusiast

 

Hello everyone,

I am trying to freeze some layers in paper layout's model viewport. 

Capture.JPG

 

 

 

With the code below, I can get all paper viewports. But I don't how to get access of model space using objectarx.

Thank you in advance.

 


static AcDbObjectIdArray GetViewportArray(AcDbLayout *pLayout) { AcDbObjectIdArray ids; AcDbBlockTableRecordPointer pBtr(pLayout->getBlockTableRecordId(), AcDb::kForRead); if (pBtr.openStatus() == Acad::eOk) { AcDbBlockTableRecordIterator *pIter = NULL; if (pBtr->newIterator(pIter) == Acad::eOk && pIter) { for (; !pIter->done(); pIter->step()) { AcDbObjectId id; if (pIter->getEntityId(id) == Acad::eOk) { if (id.objectClass() == AcDbViewport::desc()) ids.append(id); } } delete pIter; } } return ids; }

 

 

0 Likes
2,060 Views
8 Replies
Replies (8)
Message 2 of 9

tbrammer
Advisor
Advisor

You are trying to freeze some layers in a viewport. Period.

There is no seperate "model viewport" in the layout. Viewports are in the paperspace blocktablerecord of your layout.

Your code is ok - it finds the AcDbViewports within the layout.

All you have to do is to freeze the layers within the AcDbViewport. Just use the methods

 

class AcDbViewport: public AcDbEntity
{
public:
Acad::ErrorStatus freezeLayersInViewport(const AcDbObjectIdArray&); Acad::ErrorStatus thawLayersInViewport(const AcDbObjectIdArray&); Acad::ErrorStatus thawAllLayersInViewport(); bool isLayerFrozenInViewport(const AcDbObjectId& layerId) const; Acad::ErrorStatus getFrozenLayerList(AcDbObjectIdArray& ids) const;
}

Or do you plan to freeze Layers when the user changes to MSPACE and thaw them when he changes to PSPACE?

This would require a reactor.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 3 of 9

syx_lemans
Enthusiast
Enthusiast

Thank you for your reply. But I am comfused with something

AcDbObjectIdArray viewPorts = GetViewportArray(pLayout);
pLayout->close();
if (viewPorts.length() > 0) {
AcDbObjectPointer<AcDbViewport> pVport(viewPorts[0], AcDb::kForWrite);
 if (pVport.openStatus() == Acad::eOk) {
   pVport->freezeLayersInViewport(frozenLayers);
   }
}

frozenLayers is my object id array of layers.

 

My original layout is like this:

orig.JPG

 

 

 

With my application, I can creat a new layout "presentation2", and freeze the layers I want in paper space

result1.JPGresult2.JPG

 

 

 

But when I switch to model space of the same layout. I find that nothing is frozen in model space mode. result3.JPG

0 Likes
Message 4 of 9

tbrammer
Advisor
Advisor

I see what you mean.

Besides the AcDbViewport entities that you can see in your layout, there is also always the "paperspace viewport", which is an AcDbViewport as well.

This is the viewport through which you see your layout. If you freeze layers in a viewport while in paperspace you are changing this viewport.

 

I always recomment to use the great ArxDbg.arx with command SNOOPDB. You find the project in <ARX>samples\database\ARXDBG:

Vport.png

The paperspace viewport has the Number 1 (which is the content of the CVPORT variable).


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 5 of 9

syx_lemans
Enthusiast
Enthusiast

Thank you, I will try it

0 Likes
Message 6 of 9

syx_lemans
Enthusiast
Enthusiast

I've solved it by adding loop for all viewports

if (viewPorts.length() > 0) {
				for(int i =0;i<viewPorts.length();i++)
				{
					AcDbObjectPointer<AcDbViewport> pVport(viewPorts[i], AcDb::kForWrite);
					if (pVport.openStatus() == Acad::eOk) {
						pVport->freezeLayersInViewport(frozenLayers);						
					}
				}
            }
0 Likes
Message 7 of 9

Anonymous
Not applicable

Just one question to make sysvar CVPORT clear:

 

if in layout, but not in any viewport only in paperspace, CVPORT is 1

if in layout and in viewport modelspace, CVPORT is 2, 3, 4... depending which viewport - they are increased by creation chronologically

 

if in model, CVPORT is 2.

 

is this correct? what is CVPORT 1 for model?

0 Likes
Message 8 of 9

tbrammer
Advisor
Advisor

Yes, this is correct.

In "model" (TILEMODE=1)  CVPORT=1 is invalid. CVPORT=1 is the "paperspace viewport" which doesn't exist in TILEMODE=1.

You can split the model view into multiple viewports with the _VPORTS command. If you have created three viewports they will have CVPORT=2, CVPORT=3 and CVPORT=4. You can switch the active viewport by entering "CVPORT 3" or "_setvar CVPORT 3".


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 9 of 9

Anonymous
Not applicable

thanks

0 Likes