Read IFCmapconversion LISP

Deze LISP‑routine leest een IFC‑bestand, zoekt de IFCMapConversion en IFCIUnit parameters, haalt daar coördinaten, rotatie en eenheid uit, tekent hulpcirkels in de tekening en (in BricsCAD V26) zet automatisch de Project Location. Hieronder staat een duidelijke, stap‑voor‑stap uitleg van wat elk deel van de code doet.

🧩 Overzicht van de functionaliteit

De routine c:ReadIFCMapConversion doet vier dingen:

  1. Zoekt in een IFC‑bestand naar de regel met IFCMAPCONVERSION → haalt X, Y, Z, cosinus, sinus en dus de rotatiehoek op.
  2. Zoekt naar de IFCIUNIT regel → bepaalt of het model in metres of millimetres staat.
  3. Tekent drie cirkels rond het MapConversion‑punt → radii: 60 / 660 / 6660 m (of mm‑equivalent).
  4. Stelt de Project Location in (alleen BricsCAD V26) → zet het georeferentiepunt en rotatie in de tekening.
  
;;; ------------------------------------------------------------
;;; IFC MapConversion Reader + Units + Circle + ProjectLocation
;;; ------------------------------------------------------------

(defun split-by-comma (s / lst pos)
  (setq lst '())
  (while (setq pos (vl-string-search "," s))
    (setq lst (cons (substr s 1 pos) lst))
    (setq s (substr s (+ pos 2)))
  )
  (setq lst (reverse (cons s lst)))
)

(defun c:ReadIFCMapConversion ( / file path line result unitline start end params
                                   x y z cosv sinv rot unit radius)

  (setq path (getfiled "Select IFC file" "" "ifc" 0))

  (if (and path (setq file (open path "r")))
    (progn

      ;; --------------------------------------------------------
      ;; Scan IFC file for IFCMAPCONVERSION and IFCIUNIT
      ;; --------------------------------------------------------
      (while (setq line (read-line file))
        (cond
          ((wcmatch (strcase line) "*IFCMAPCONVERSION(*")
           (setq result line)
          )
          ((and (wcmatch (strcase line) "*IFCIUNIT(*")
                (wcmatch (strcase line) "*,.LENGTHUNIT.,*"))
           (setq unitline line)
          )
        )
      )
      (close file)

      ;; --------------------------------------------------------
      ;; Extract units from IFCIUNIT
      ;; --------------------------------------------------------
      (if unitline
        (progn
          (setq start (vl-string-search "(" unitline))
          (setq end   (vl-string-search ")" unitline))
          (setq params (substr unitline (+ start 2) (- end start 1)))
          (setq params (split-by-comma params))
          (setq unit (nth 3 params))   ;; .METRE. or .MILLIMETRE.
        )
        (setq unit ".METRE.") ;; fallback
      )

      ;; --------------------------------------------------------
      ;; Extract IFCMAPCONVERSION parameters
      ;; --------------------------------------------------------
      (if result
        (progn
          (setq start (vl-string-search "(" result))
          (setq end   (vl-string-search ")" result))
          (setq params (substr result (+ start 2) (- end start 1)))
          (setq params (split-by-comma params))

          ;; X, Y, Z
          (setq x (atof (nth 2 params)))
          (setq y (atof (nth 3 params)))
          (setq z (atof (nth 4 params)))

          ;; cos & sin
          (setq cosv (atof (nth 5 params)))
          (setq sinv (atof (nth 6 params)))

          ;; Rotation in degrees
          (setq rot (* 180.0 (/ (atan sinv cosv) pi)))

          ;; --------------------------------------------------------
          ;; Draw circle (60 m or 60000 mm)
          ;; --------------------------------------------------------
          (setq radius (if (= (strcase unit) ".METRE.") 60.0 60000.0))
          (setq radius1 (if (= (strcase unit) ".METRE.") 660.0 660000.0))
          (setq radius2 (if (= (strcase unit) ".METRE.") 6660.0 6660000.0))



          (command "_.CIRCLE" (list x y z) radius)
          (command "_.CIRCLE" (list x y z) radius1)
          (command "_.CIRCLE" (list x y z) radius2)


          ;; --------------------------------------------------------
          ;; Set project location (BricsCAD V26 only)
          ;; --------------------------------------------------------
          (if (= (atoi (substr (getvar "ACADVER") 1 2)) 26)
           (command "_.SETPROJECTLOCATION" "POINT" (strcat (rtos x 2 6) "," (rtos y 2 6) "," (rtos z 2 6)) "angle" (rtos rot 2 8) "") 
          )

          ;; --------------------------------------------------------
          ;; Final message
          ;; --------------------------------------------------------
          (alert
            (strcat
              "IFCMapConversion found:\n"
              result
              "\n\nXYZ: " (rtos x 2 3) ", " (rtos y 2 3) ", " (rtos z 2 3)
              "\nRotation (deg): " (rtos rot 2 8)
              "\n\nModel units: " unit
              "\nCircle drawn with radius: "
              "\nProject location set (if in BricsCAD V26)."
            )
          )
        )
        (alert "No IFCMapConversion found in this IFC file.")
      )
    )
    (alert "No file selected.")
  )
  (princ)
)


      
   
  
Dutch NL English EN German DE