AnsweredAssumed Answered

GetObjectByPersistReference3 fails for ref I just got (in Assembly)

Question asked by Greg James on May 30, 2017
Latest reply on Jun 1, 2017 by Greg James

The following code throws my exception when run from an Assembly.

Why does the ModelDoc2 not accept a persistreference3 that it just handed me?

 

        const int PERSIST_REF_OBJ_OK = (int)swPersistReferencedObjectStates_e.swPersistReferencedObject_Ok;

 

        public List<object> SegmentsToPersistRefs(List<SketchSegment> segments)

        {

            Debug.Print("SegmentsToPersistRefs called for list of " + segments.Count);

            List<object> refs = new List<object>();

            foreach (SketchSegment seg in segments)

            {

                object pid = mDoc.Extension.GetPersistReference3(seg);

                if (pid == null)

                {

                    throw new ApplicationException("SketchSegment GetPersistReference3 is null");

                }

 

                int errorCode;

                object obj = mDoc.Extension.GetObjectByPersistReference3(pid, out errorCode);

                if (errorCode != PERSIST_REF_OBJ_OK)

                {

                    // *** ENDS UP HERE with errorCode = 1 == INVALID ***

                    throw new ApplicationException("Cannot get object from PersistRef3 we just got");

                }

                refs.Add(pid);

            }

            return refs;

        }

Outcomes