Custom Objects With Dependencies And Filing

Custom Objects With Dependencies And Filing

christineweiss86
Contributor Contributor
761 Views
3 Replies
Message 1 of 4

Custom Objects With Dependencies And Filing

christineweiss86
Contributor
Contributor

Hello,

I am trying to explain this as short and exact as I can. 

My tool contains various custom objects that depend on each other. So I am inserting them in the right order. When I am saving my drawing and try to reopen it, the dwginfields Methods of the objects get called in a different order, so that my objects cannot be initiated completely. I am trying to use an AcRxEventReactor with the Event initialDwgFileOpenComplete to complete my initiation there, but I encounter two huge problems:

  1. Somehow my Reactor detaches itself after I closed all open Drawings (but the AutoCAD application is still running). I use autoInitAndRelease = true.
  2. I need to store lists of my objects, that I depend on, per document. How can I achieve this in DBX since there is no document class available?

I am open for other ideas to get the saving and loading done with dependencies. Maybe I can change the order in which dwginfields methods are called, but I couldn't find a way.

I would appreciate your help.

 

Kind Regards

Christine

0 Likes
Accepted solutions (1)
762 Views
3 Replies
Replies (3)
Message 2 of 4

tbrammer
Advisor
Advisor
Accepted solution

@1: What do you mean by "the reactor detaches itself"? Do you mean, that initialDwgFileOpenComplete() won't be called for any new document after you closed all docs? Is the destructor of your AcRxEventReactor called?

 

@2: You could use a std::map<AcDbDatabase*, MyDocData> in your DBX to map your document data to an AcDbDatabase like this:

std::map<AcDbDatabase*, MyDocData> DocDataMap;

void f(AcDbEntity *ent)
{
     MyDocData &data = DocDataMap[ent->database()];
}

 


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

Message 3 of 4

christineweiss86
Contributor
Contributor

Thank you very much for your help! I am now using the databaseConstructed method to create a new entry in my map and I am storing this map in a static class that all my custom entities that need data from the ElementContainer have access to:

 

databaseConstructed(AcDbDatabase* pDatabase) {
   PProDocManager::pElementContainer[pDatabase] = new PProElementContainer();
}
class PProDocManager
{
public:
	 static std::map<AcDbDatabase*,PProElementContainer*> pElementContainer;
public:	 
	 ~PProDocManager(void);

	 static PProElementContainer* getpElementContainer(AcDbDatabase* pDatabase);
private:
	 PProDocManager(void);
};
#include "stdafx.h"
#include "PProDocManager.h"

std::map<AcDbDatabase*,PProElementContainer*> PProDocManager::pElementContainer;

PProDocManager::PProDocManager(void)
{
}


PProDocManager::~PProDocManager(void)
{
}


PProElementContainer* PProDocManager::getpElementContainer(AcDbDatabase* pDatabase) {
	 std::map<AcDbDatabase*, PProElementContainer*>::const_iterator iterMap = pElementContainer.find(pDatabase);
	 //Element found
	 if(iterMap != pElementContainer.end()) {
		  return iterMap->second;
	 }
	 else {
		  return nullptr;
	 }
}

 The problem with the EventReactor is gone. Maybe it was a consecutive fault caused by my other problems in the code.

Thanks again!

0 Likes
Message 4 of 4

Anonymous
Not applicable

This is work fine https://www.welookups.com

#include "stdafx.h"
#include "PProDocManager.h"

std::map<AcDbDatabase*,PProElementContainer*> PProDocManager::pElementContainer;

PProDocManager::PProDocManager(void)
{
}


PProDocManager::~PProDocManager(void)
{
}


PProElementContainer* PProDocManager::getpElementContainer(AcDbDatabase* pDatabase) {
	 std::map<AcDbDatabase*, PProElementContainer*>::const_iterator iterMap = pElementContainer.find(pDatabase);
	 //Element found
	 if(iterMap != pElementContainer.end()) {
		  return iterMap->second;
	 }
	 else {
		  return nullptr;
	 }
}

 

0 Likes