Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Catch other object's delete/undo

    Cinema 4D SDK
    c++ r19 r20 r21
    2
    5
    882
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rsodreR
      rsodre
      last edited by

      Hello,

      I have a generator that contains an InExclude list where I can add polygons, and I create my own mesh over those polygons. When a polygon from my list is deleted from the scene, it is not deleted from the list, and my mesh becomes outdated, it has some faces that should not exist anymote. Anyone would expect my mesh to be updated right away, so I need to manually check if there's any null object in the list, remove it, delete some data that was generated for that polygon, and recompute my mesh. I'm doing this in Execute() and is working good.

      The problem is when the user hits Undo after that. The original polygon is back, but the operation I did on my generator (delete the polygon from the list and updated data) is not.
      When I'm updating my list, BaseDocument:: GetUndoPtr() returns nothing (and would not be of great help).
      Adding a new Undo step triggers a debug breakpoint (CRITICAL: Stop), and the step is not created.

      I need some understanding how can I not lose any data when that original polygon is deleted.
      Is there a better way to catch the delete?
      Is there a way to catch that polygon Undo and add my generator to it? The polygons are added as dependencies but no messages are sent to my generator.
      Should I add a new undo step? Where?

      Thanks,
      Roger

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @rsodre just some clarification:

        "I can add polygons". Do you mean PolygonObject or PolygonSelection?

        Thanks in advance.
        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • rsodreR
          rsodre
          last edited by

          Hi @m_adam

          I add PolygonObjects to the InExclude list.

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by m_adam

            Hi @rsodre do you have some minimal code to reproduce?

            "I need some understanding of how can I not lose any data when that original polygon is deleted." This part is really not clear since you said that you manually delete if the original polygonObj is deleted, if you don't want to lose your data, then copy them into a local variable?

            You can be informed of an undo with MSG_DOCUMENTINFO and listen to MSG_DOCUMENTINFO_TYPE_UNDO.

            An idea you could also AddEventNotification to redirect undo, but use it as the last way to do since it can really screw-up things and without a clear example it's pretty hard for me to guide you.

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • rsodreR
              rsodre
              last edited by

              @m_adam , AddEventNotification was exactly what I needed. I created a notification to NOTIFY_EVENT_UNDO, and then add my object to it. Now if I delete anything from my object after a polygon is deleted, it will be restored with Undo.

              Thanks!

              case MSG_NOTIFY_EVENT:
              {
              	CHECK_BREAK( data != nullptr );
              	const auto eventData = static_cast<NotifyEventData*>( data );
              	if( eventData->eventid == NOTIFY_EVENT_UNDO )
              	{
              		NotifyEventMsg* notifyMessage = static_cast<NotifyEventMsg*>( eventData->event_data );
              		CHECK_BREAK( notifyMessage != nullptr );
              		if( notifyMessage->msg_id == Int32( UNDOTYPE_DELETE ) )
              		{
              			eventData->doc->AddUndo( UNDOTYPE_CHANGE, Get() );
              		}
              	}
              	break;
              }
              
              1 Reply Last reply Reply Quote 1
              • First post
                Last post