TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mkweaver 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:
(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:
((-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")
)
-
Maybe you can post a simple drawing to test your code out on.
-
Maybe you can post a simple drawing to test your code out on.
What is the best way for me to post a file?
-
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 :
-
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
-
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.
-
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.
(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)
)
-
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:-(
(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.