Jump to content

Dyanically setting tree trunk and diameter.


BIGAL

Recommended Posts

Following on from posts by YZ and the need to update some blocks enthused me to look at a problem with CIV3d to do with trees, via a PM I know Lee has helped YZ to do the following for export from Magnet. This will find cogo_points and add a dynamic block for tree trunk size and spread based on the point description. ie an inner and outer shape.

 

Just a quick comment we have a 3rd party app that did work and when it was updated it stopped working.

 

; Dynamically insert a tree based on civ3D point description 
; By Alan H Sep 2016
; version 2 read a csv file for non Civ3D users
;; Set Dynamic Block Property Value  -  Lee Mac
;; Modifies the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; val - [any] New value for property
;; Returns: [any] New value if successful, else nil
(defun LM:setdynpropvalue ( blk prp val )
   (setq prp (strcase prp))
   (vl-some
      '(lambda ( x )
           (if (= prp (strcase (vla-get-propertyname x)))
               (progn
                   (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
                   (cond (val) (t))
               )
           )
       )
       (vlax-invoke blk 'getdynamicblockproperties)
   )
)
;; CSV -> List  -  Lee Mac
;; Parses a line from a CSV file into a list of cell values.
;; str - [str] string read from CSV file
;; sep - [str] CSV separator token
;; pos - [int] initial position index (always zero)

(defun LM:csv->lst ( str sep pos / s )
   (cond
       (   (not (setq pos (vl-string-search sep str pos)))
           (if (wcmatch str "\"*\"")
               (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2))))
               (list str)
           )
       )
       (   (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]")
               (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos)))
           )
           (LM:csv->lst str sep (+ pos 2))
       )
       (   (wcmatch s "\"*\"")
           (cons
               (LM:csv-replacequotes (substr str 2 (- pos 2)))
               (LM:csv->lst (substr str (+ pos 2)) sep 0)
           )
       )
       (   (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0)))
   )
)
(defun dynamic_trees ( / obj obj2 raw inspt )
;(if (not LM:csv->lst)(load "ReadCSV-V1-3"))
;(if (not LM:setdynpropvalue)(load "set-dynamic-block-value"))
(setq layold (getvar "clayer"))
(if (not (tblsearch "LAYER" "EX_TREE"))
    (Command "-layer" "m" "EX_TREE" "c" 90 "EX_TREE" "LT" "Continuous" "EX_TREE" "")
    (setvar "clayer" "EX_TREE")
)
(setq ss (ssget "x" '((0 . "AECC_COGO_POINT"))))
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq raw (vla-get-description obj))
(setq inspt (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'location))))
;RawDescription = "TR 5 1.5" replace tr as required add extra tree types also
; use space delimeted description - tree trunk spread
(if (wcmatch raw "TR*") 
(progn
(setq rawlist (LM:csv->lst raw " " 0))
(setq basedesc (nth 0 rawlist))
(setq spread (atof (nth 2 rawlist)))
(setq trunk (atof (nth 1 rawlist))) ; convert string
(if (= "TR" basedesc)
(progn
(command "-Insert" "TREEDYN" inspt 1 1 0)
(setq obj2 (vlax-ename->vla-object (entlast)))
(LM:setdynpropvalue obj2 "Trunk" trunk)
(LM:setdynpropvalue obj2 "Spread" spread)
) ;progn
) ; if
) ;progn
) ; if
) ; repeat
(setvar "clayer" layold)
(princ) ; exit quitely
) ;defun
(dynamic_trees)

treedyn.dwg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...