TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CAB on August 20, 2008, 04:20:00 PM

Title: Challenge: Dim Reactor
Post by: CAB on August 20, 2008, 04:20:00 PM
Those of us that use Architectural units typically dimension with feet and inches.
Using smaller dimensions, less than 2 feet, it is desirable in some cases to have the dimension in Inches only.
Seeing a comment on another forum gave me the idea that a reactor might be constructed to change the
dimension over ride to display inches and add the inch character as the suffix.

So the challenge would be to create a reactor to do just that for any command that created a dimension or
edited a dimension. There should be a user changeable threshold for the reactor to switch the dimension to inches
or back to feet & inches. There should also be a list of user supplied Dim Styles that would filter for allowable
Dim Styles. This would prevent some styles from being modified.

I would say that this is probably an advanced level challenge.
Anyone interested?
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 20, 2008, 04:26:39 PM
Similar or like what this person did and posted here?

http://www.theswamp.org/index.php?topic=9441.msg234800#msg234800

Maybe?

And he put it here:

http://www.theswamp.org/index.php?topic=9441.msg140392#msg140392
Title: Re: Challenge: Dim Reactor
Post by: CAB on August 20, 2008, 04:46:17 PM
Yes Luis, I did not see that code.

PS I won't be able to test it tonight as I'm out till late.
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 20, 2008, 04:59:24 PM
Yes Luis, I did not see that code.

PS I won't be able to test it tonight as I'm out till late.



Alan,

Hope that helps... :)
Title: Re: Challenge: Dim Reactor
Post by: CAB on August 20, 2008, 07:50:13 PM
Just got in, that will likely do just fine.
I did not plan on writing the code I just though it would be a good challenge.
I'm hoping some folks may have an intrest in the writing of the code.
Title: Re: Challenge: Dim Reactor
Post by: CAB on August 21, 2008, 09:20:42 AM
See attached a copy of the lisp with the variables corrected as they were wrong type. Luis pointed this out.

Works well Luis, but there are some items that don't match my requirements.
I'm not asking Luis to alter the lisp. Just seeing if someone else wants to give it a go.

Routine does not alter the Dimension if it is modified, only when created.
Routine does not honer specific Dim Styles, works on all Dim Styles.
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 21, 2008, 09:51:45 AM
Just got in, that will likely do just fine.
I did not plan on writing the code I just though it would be a good challenge.
I'm hoping some folks may have an intrest in the writing of the code.

That code can be use as a start.... :)
Title: Re: Challenge: Dim Reactor
Post by: CAB on August 21, 2008, 09:57:29 AM
Yes, you did the hard part. 8-)
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 21, 2008, 10:12:18 AM
Yes, you did the hard part. 8-)

:)

Quote
Routine does not alter the Dimension if it is modified, only when created.
Routine does not honer specific Dim Styles, works on all Dim Styles.

Those two can be very easy to add..... (that's what I miss from lisp)

Let's see/wait if any other swamper come up with a solution...  :mrgreen:
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 21, 2008, 04:41:35 PM
The problem, is going to be in the "modified" event - owner is not open for write... and has to be included in a list and later do the updates from probably the Regen command (at the commandended event)... as far I recall
Title: Re: Challenge: Dim Reactor
Post by: POCKETS on August 21, 2008, 05:27:57 PM
Cab,
I downloaded your fractdims.lsp but I can't get it to work.  I am looking for a "defun c" but there doesn't seem to be one.  Is there another way to get fractdims.lsp to work?   :|
Pockets
Title: Re: Challenge: Dim Reactor
Post by: CAB on August 21, 2008, 05:30:41 PM
LE (luis) wrote the routine. It is a reactor, so just load it.
When you create a dimension < 48" it should show inches.
If the dim is > 48" it should show as set up in the Dim Style.
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 21, 2008, 05:46:22 PM
Cab,
I downloaded your fractdims.lsp but I can't get it to work.  I am looking for a "defun c" but there doesn't seem to be one.  Is there another way to get fractdims.lsp to work?   :|
Pockets

As Alan already mentioned.... and you can read the settings on top of the file ie:

Quote
;; variables
(setq auto_fract T) ;; ON === By simple changing this to nil (setq auto_fract nil) it will turn off the feature (not the reactor)
(setq min_dim_tol "0.25")
(setq max_dim_tol "48.0")
(setq dim_radius_suffix "\"")
(setq dim_radius_prefix "R=")
(setq dimstyles (list "DIM-1" "DIM-48" "DIM-96" "DIM-32")) N/A

Change the variables to suit your needs... hth
Title: Re: Challenge: Dim Reactor
Post by: CAB on August 21, 2008, 06:03:37 PM
Here is a modified version.
If you stretch the dimension to <=48" it will change to inches.
But stretching the other way does not work yet. I'm pondering what to do when there are existing xdata overrides present.
The current routine overwrites existing xdata.

This is a test release.
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 21, 2008, 07:00:54 PM
Here is a modified version.
If you stretch the dimension to <=48" it will change to inches.
But stretching the other way does not work yet. I'm pondering what to do when there are existing xdata overrides present.
The current routine overwrites existing xdata.

This is a test release.

Alan,

have a look at this update, it works here back and forward, and even with matchprop too... please ignore the code enchilada I just did.

Notes:
1. I did not understood the cond usage the part "AcDbRadialDimension" - I thought that was taking care on "DIMRADIUS" - me might wrong.

2. I reuse my previous if's calls

3. Added a new function to change the xdata, but this can be place on a single function, merge fractional-dim and fractional-dim-arch

4. hth

5. almost forgot.... so where are the swamp lispers ?
Title: Re: Challenge: Dim Reactor
Post by: T.Willey on August 21, 2008, 07:43:08 PM
5. almost forgot.... so where are the swamp lispers ?

I was looking at one way while trying to get my work done, need to keep my job and all.  I haven't figured it out yet, but I think it will work sweet when I get it there.  Hopefully tomorrow.
Title: Re: Challenge: Dim Reactor
Post by: Kerry on August 21, 2008, 07:49:04 PM

5. almost forgot.... so where are the swamp lispers ?

Some of us have real work that needs doing ...

and other languages to study  :-)
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 21, 2008, 07:52:40 PM
I only asked where there were.....  :-P
Title: Re: Challenge: Dim Reactor
Post by: CAB on August 21, 2008, 08:30:31 PM
Luis,
I decided to make a major revision in the commandended routine.

See if you can break it.

<edit: renamed lisp file>
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on August 21, 2008, 10:25:37 PM
Luis,
I decided to make a major revision in the commandended routine.

See if you can break it.


That's the right way..... Cheers!
Title: Re: Challenge: Dim Reactor
Post by: TimSpangler on August 22, 2008, 07:10:43 AM
so where are the swamp lispers ?

Working.......  :|
Title: Re: Challenge: Dim Reactor
Post by: Chuck Gabriel on August 22, 2008, 07:12:39 AM
Some of us have real work that needs doing ...

Get your priorities straight Kerry. :-P
Title: Re: Challenge: Dim Reactor
Post by: T.Willey on August 22, 2008, 06:03:48 PM
Here is one that seems to be working.  It has two variables that you can control which dims get edited.  There is the 'MinLength' and the 'IgnoreDimStyleList'.  Let me know.  I know if can be cleaned up a bit, but for now it works.   :-D

Code: [Select]
(or
    GlbVarReactObjectAdded
    (setq GlbVarReactObjectAdded (vlr-acdb-reactor "DimObjectReactor" '((:vlr-objectAppended . ObjectAppenedReact))))
)
(defun ObjectAppenedReact (react objList / CorrectionList EntData tempList tempSubList tempList2)
   
    (setq CorrectionList
        (list
            -3
            (list
                "ACAD"
                '(1000 . "DSTYLE")
                '(1002 . "{")
                '(1070 . 3)
                '(1000 . "\"")
                '(1070 . 277)
                '(1070 . 2)
                '(1002 . "}")
            )
        )
    )
    (foreach i objList
        (if
            (and
                (equal (type i) 'ENAME)
                (= (cdr (assoc 0 (setq EntData (entget i '("*"))))) "DIMENSION")
                (not (member (cdr (assoc 3 EntData)) IgnoreDimStyleList))
            )
            (progn
                (if (< (cdr (assoc 42 EntData)) MinLength)
                    (if (setq tempList (assoc -3 EntData))
                        (if (setq tempSubList (assoc (caadr CorrectionList) (cdr tempList)))
                            (if (not (equal (cadr CorrectionList) tempSubList))
                                (entmod
                                    (subst
                                        (subst (cadr CorrectionList) tempSubList tempList)
                                        tempList
                                        EntData
                                    )
                                )
                            )
                            (entmod (subst (cons -3 (append (cadr tempList) (cadr CorrectionList))) tempList EntData))
                        )
                        (entmod (append EntData (list CorrectionList)))
                    )
                    (if (setq tempList (assoc -3 EntData))
                        (progn
                            (foreach i (cdr tempList)
                                (if (equal (cadr CorrectionList) i)
                                    (setq tempList2 (cons (list (car i)) tempList2))
                                    (setq tempList2 (cons i tempList2))
                                )
                            )
                            (entmod (subst (cons -3 (reverse tempList2)) tempList EntData))
                        )
                    )
                )
                (if react
                    (vlr-pers
                        (vlr-object-reactor
                            (list (vlax-ename->vla-object i))
                            "DimObjectReactor"
                            '(
                                (:vlr-objectClosed . ObjectModifiedDone)
                                (:vlr-erased . ObjectEraseReactor)
                            )
                        )
                    )
                )
            )
        )
    )
    (and
        GlbVarDimReactCommandEnded
        (vlr-remove GlbVarDimReactCommandEnded)
    )
    (setq GlbVarDimReactCommandEnded nil)
    (setq GlbVarDimReactEntList nil)
    (princ)
)
(defun ObjectModifiedDone (ownObj react tempList)
   
    (setq GlbVarDimReactEntList (cons (vlax-vla-object->ename ownObj) GlbVarDimReactEntList))
    (or
        GlbVarDimReactCommandEnded
        (setq GlbVarDimReactCommandEnded (vlr-command-reactor "tempDimReactCommandEnded" '((:vlr-commandEnded . DimReactCommandEnded))))
    )
    (princ)
)
(defun DimReactCommandEnded (react cmdNames)
   
    (foreach i GlbVarDimReactEntList
        (ObjectAppenedReact nil (list i))
    )
    (princ)
)
(defun ObjectEraseReactor (Obj React NotSure)
   
    (vlr-pers-release React)
    (vlr-remove React)
)
Title: Re: Challenge: Dim Reactor
Post by: whdjr on September 24, 2008, 08:04:47 AM
so where are the swamp lispers ?
Some of us have no clue about reactors.  :-(
Title: Re: Challenge: Dim Reactor
Post by: Alan Cullen on September 24, 2008, 08:44:01 AM
Hey...I'm a Swamp Lisper....

What is a reactor?

Sorry...I was asleep that day.
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on September 24, 2008, 09:34:13 AM
so where are the swamp lispers ?
Some of us have no clue about reactors.  :-(

:)

no problema, it was just a 'tag' to get more attention to this thread/topic.

i had a lot of clues, but most of them are now lost... there are many samples posted here 'about reactors'
Title: Re: Challenge: Dim Reactor
Post by: Spike Wilbury on September 24, 2008, 09:49:21 AM
What is a reactor?

many autocad commands are made with reactors, like leaders, dimensions, etc. to mention a few... with the intro of vital lisp (later renamed to visual lisp) reactors were available for autolisp to make more intelligent alike routines... in example the ability to place automatic dimensions on one or multiple entities, right after a modification or when an specific command ended, or right before closing a drawing to be able to make last corrections before closing it,  etc. etc etc.

now, there are the 'fields' objects, so many things can be used with these objects...

hth.