Author Topic: Copy settings from one sectionplane to another - I'm stuck  (Read 2872 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
Copy settings from one sectionplane to another - I'm stuck
« on: October 18, 2010, 08:20:15 PM »
The following code was intended to copy the section generation settings from one section plane to another.  It's not working as intended.  When I select the source sectionplane object then the target and turn it loose I get an error about a "multiply owned object".
In the settings object dxf list I can see the pointer back to it's owner, so I thought I would simply have to replace that with a pointer to the target object.  Apparently something else is neaded.

Any suggestions are welcome:
Code: [Select]
(defun c:msp( / ListOfChangedEntities elist2 ent settings ss1 ss2) ;Match Section Properties
  (princ "\nSelect source section object: ")
  (cond
    ((null (setq ss1 (vl-catch-all-apply 'ssget (list ":S" '((0 . "SECTIONOBJECT"))))))
     nil
     )
    ((vl-catch-all-error-p ss1)
     (princ (strcat "\nERROR|" (vl-catch-all-error-message ss1)))
     nil
     )
    ((and
       (= 'PICKSET (type ss1))
       (= 0 (sslength ss1))
       )
     nil
     )
    (T
     (setq
       Settings (cdr (assoc 360 (entget (ssname ss1 0))))
       )
     ;;While the operator selects target section objects
     (while
       (cond
((not (princ "\nSelect target section objects: ")))
((null (setq ss2 (vl-catch-all-apply 'ssget (list ":S" '((0 . "SECTIONOBJECT"))))))
  T
  )
((vl-catch-all-error-p ss2)
  (princ (strcat "\nERROR|" (vl-catch-all-error-message ss2)))
  nil
  )
((and
    (= 'PICKSET (type ss2))
    (= 0 (sslength ss2))
    )
  T
  )
(T
  (setq
    ent (ssname ss2 0)
    ListOfChangedEntities (cons ent ListOfChangedEntities)
    )
  ;;Fix this code so the entity pointed to by the settings is re-created with entmake
  ;;currently this results in a multiply owned object each time the routine runs.
  (entmod (subst (cons 360 settings) (assoc 360 (setq elist2 (entget ent))) elist2))
  T
  )
)
       ) ;end while
     (princ (strcat "\nModified " (itoa (length listofchangedentities)) " objects."))
     ) ;end T - valid initial selection
    ) ;end outer cond
  (princ)
  )


And the dxf list for the settings object:
Code: [Select]
((-1 . <Entity name: 7fff616f700>)
  (0 . "SECTION_SETTINGS")
  (330 . <Entity name: 7fff616f6b0>)
  (5 . "9F00")
  (100 . "AcDbSectionSettings")
  (90 . 2)
  (91 . 1)
  (1 . "SectionTypeSettings")
  (90 . 2)
  (91 . 17)
  (92 . 0)
  (331 . <Entity name: 0>)
  (1 . "")
  (93 . 4)
  (2 . "SectionGeometrySettings")
  (90 . 2)
  (91 . 1)
  (92 . 8)
  (62 . 256)
  (8 . "G-DETL-HEVY")
  (6 . "ByLayer")
  (40 . 1.0)
  (1 . "ByColor")
  (370 . -1)
  (70 . 0)
  (71 . 0)
  (72 . 0)
  (2 . "")
  (41 . 0.0)
  (42 . 1.0)
  (43 . 1.0)
  (3 . "SectionGeometrySettingsEnd")
  (2 . "SectionGeometrySettings")
  (90 . 2)
  (91 . 2)
  (92 . 5)
  (62 . 9)
  (420 . 13158600)
  (8 . "G-DETL-XLIT")
  (6 . "ByLayer")
  (40 . 1.0)
  (1 . "ByColor")
  (370 . -1)
  (70 . 0)
  (71 . 0)
  (72 . 1)
  (2 . "SOLID")
  (41 . 0.0)
  (42 . 1.0)
  (43 . 1.0)
  (3 . "SectionGeometrySettingsEnd")
  (2 . "SectionGeometrySettings")
  (90 . 2)
  (91 . 4)
  (92 . 1)
  (62 . 256)
  (8 . "G-DETL-LITE")
  (6 . "Continuous")
  (40 . 1.0)
  (1 . "ByColor")
  (370 . -1)
  (70 . 0)
  (71 . 0)
  (72 . 0)
  (2 . "")
  (41 . 0.0)
  (42 . 1.0)
  (43 . 1.0)
  (3 . "SectionGeometrySettingsEnd")
  (2 . "SectionGeometrySettings")
  (90 . 2)
  (91 . 16)
  (92 . 1)
  (62 . 256)
  (8 . "G-DETL-XLIT")
  (6 . "ByLayer")
  (40 . 1.0)
  (1 . "ByColor")
  (370 . -1)
  (70 . 0)
  (71 . 0)
  (72 . 0)
  (2 . "")
  (41 . 0.0)
  (42 . 1.0)
  (43 . 1.0)
  (3 . "SectionGeometrySettingsEnd")
  (3 . "SectionTypeSettingsEnd")
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy settings from one sectionplane to another - I'm stuck
« Reply #1 on: October 19, 2010, 12:17:55 PM »
Maybe you can post a simple drawing to test your code out on.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

mkweaver

  • Bull Frog
  • Posts: 352
Re: Copy settings from one sectionplane to another - I'm stuck
« Reply #2 on: October 19, 2010, 11:53:43 PM »
Maybe you can post a simple drawing to test your code out on.

What is the best way for me to post a file?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copy settings from one sectionplane to another - I'm stuck
« Reply #3 on: October 20, 2010, 12:21:41 AM »


Maybe you can post a simple drawing to test your code out on.

What is the best way for me to post a file?

Try this :
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

mkweaver

  • Bull Frog
  • Posts: 352
Re: Copy settings from one sectionplane to another - I'm stuck
« Reply #4 on: October 20, 2010, 12:24:22 AM »
Thanks for the attachment instructions.

Here is my sample drawing.  There are two sectionplane objects.  I need my routine to copy the section generation settings from one sectionplane object to the other.

Thanks for taking a look at this.

Mike

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy settings from one sectionplane to another - I'm stuck
« Reply #5 on: October 20, 2010, 11:56:29 AM »
For some reason I was not able to open the drawing.  I'm on '09 still, and when I converted it with True View, the drawing would crash Acad each time I tried to open it.  I even did a recover on the drawing, it found no errors, but then crashed Acad still.

I guess I'm asking for another sample, or I would have to try and create one, but I have never used section planes, so I wouldn't know where to look to create one, and what it is used for.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy settings from one sectionplane to another - I'm stuck
« Reply #6 on: October 20, 2010, 12:18:05 PM »
This seems to work on a simple drawing, but you might want to test it to see if it really works, as I didn't make anything as complex as what you showed in your first post.

Code: [Select]
(defun c:Test ( / CpEnt TrgEnt Data CpData )
   
    (if
        (and
            (setq CpEnt (car (entsel "\n Select source section object: ")))
            (setq TrgEnt (car (entsel "\n Select target section object: ")))
        )
        (setq Data (entget (cdr (assoc 360 (entget CpEnt)))))
        (setq CpData (entget CpEnt))
        (entmod
            (subst
                (cons
                    360
                    (entmakex
                        (subst
                            (cons 330 CpEnt)
                            (assoc 330 Data)
                            Data
                        )
                    )
                )
                (assoc 360 CpData)
                CpData
            )
        )
    )
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

mkweaver

  • Bull Frog
  • Posts: 352
Re: Copy settings from one sectionplane to another - I'm stuck
« Reply #7 on: October 20, 2010, 09:57:39 PM »
Interesting.  I couldn't get your code to work.

I tweaked mine to come at it from a different direction, but haven't gotten it to work yet:-(

Code: [Select]
(defun c:msp( / ListOfChangedEntities elist2 ent settings ss1 ss2) ;Match Section Properties
  (princ "\nSelect source section object: ")
  (cond
    ;;Did we select anything?
    ((null (setq ss1 (vl-catch-all-apply 'ssget (list ":S" '((0 . "SECTIONOBJECT"))))))
     nil
     )
    ;;Did we cancel at the select objects prompt?
    ((vl-catch-all-error-p ss1)
     (princ (strcat "\nERROR|" (vl-catch-all-error-message ss1)))
     nil
     )
    ;;Was anything pre-selected?
    ((and
       (= 'PICKSET (type ss1))
       (= 0 (sslength ss1))
       )
     nil
     )
    ;;We selected something, let's move on
    (T
     (setq Settings (cdr (assoc 360 (entget (ssname ss1 0)))))
     ;;While the operator selects target section objects
     (while
       (cond
;;Provide a prompt
((not (princ "\nSelect target section objects: ")))
;;Select a sectionobject
((null (setq ss2 (vl-catch-all-apply 'ssget (list ":S" '((0 . "SECTIONOBJECT"))))))
  T
  )
;;Did we cancel?
((vl-catch-all-error-p ss2)
  (princ (strcat "\nERROR|" (vl-catch-all-error-message ss2)))
  nil
  )
;;Was anything pre-selected?
((and
    (= 'PICKSET (type ss2))
    (= 0 (sslength ss2))
    )
  T
  )
;;We selected a valid target, let's move on
(T
  (setq
    ent (ssname ss2 0)
    ListOfChangedEntities (cons ent ListOfChangedEntities)
    TargetSettings (cdr (assoc 360(entget ent)))
    )[color=red]
  ;;old code -
  ;;(entmod (subst (cons 360 settings) (assoc 360 (setq elist2 (entget ent))) elist2))
  ;;Cycle through all the settings, changing only those in our include list
  (entmod
    (mapcar
      (function
(lambda(SourceCode TargetCode)
  ;;If this is in our include list
  (if (member (car SourceCode) '(2 6 8 62 420))
    SourceCode
    TargetCode
    ) ;end if
  ) ;end lambda
) ;end function
      (entget Settings) ;The settings from the source
      (entget TargetSettings) ;the settings from the target
      ) ;end mapcar
    ) ;end entmod[/color] ) ;end cond T
) ;end cond
       ) ;end while
     (princ (strcat "\nModified " (itoa (length listofchangedentities)) " objects."))
     ) ;end T - valid initial selection
    ) ;end outer cond
  (princ)
  )

Modified code in red.