Jump to content

Recommended Posts

Posted

I've created a script to grab a TIFF mapping from a postcode, which will gab the "NE, NW, SE & SW" mapping for the grid reference which i would like to insert into a cad file at a specific location defined by a mouse click, or either its geo location (not sure what this is called but when i xref these images in there go to a specific point themselves)

 


 

(defun JH:insert-mapping (reference)
  (setq NE (strcat (apply 'strcat reference) "NE ")
        NW (strcat (apply 'strcat reference) "NW ")
        SE (strcat (apply 'strcat reference) "SE ")
        SW (strcat (apply 'strcat reference) "SW ")
        symbol (substr NE 1 2)
  )
  
  (setq NEpath (strcat "Z:\\path\\Mapping\\data\\" symbol "\\" NE))
  
  (command "IMAGE" "-point" (getpoint "\nInsertion point") "-insert" NEpath)

  ;(princ (strcat NE "\n" NW "\n" SE "\n" SW))
)

 

Posted

Would need to see a the tiff. and make sure everything is to the proper scale.

 

(defun JH:insert-mapping (reference)
  ...
  (if 
    (and 
      (findfile (setq NEpath (strcat "Z:\\path\\Mapping\\data\\" symbol "\\" NE))) ;does file exist
      (setq pt (getpoint "\nInsertion point"))
    )
    (progn
      (command "IMAGE" "-point" "_non" pt "-insert" NEpath)
      (setq tif (vlax-ename->vla-object (entlast)))
      (vla-getboundingbox tif'minpt 'maxpt)
      (setq LL (vlax-safearray->list minpt)
            UR (vlax-safearray->list maxpt)
            LR (list (car UR) (cadr LL))
            UL (list (car LL) (cadr UR))
      )
    )
  )
  ;Depending on what image was inserted
  (vla-move tif LR pt) ;move image NW
  (vla-move tif UR pt) ;move image SW
  (vla-move tif LL pt) ;move image NE
  (vla-move tif UL pt) ;move image SE
 ;(princ (strcat NE "\n" NW "\n" SE "\n" SW))
) 

 

Posted (edited)

delete - see below

Edited by Charpzy
Posted (edited)
13 minutes ago, mhupp said:

Would need to see a the tiff. and make sure everything is to the proper scale.

 

(defun JH:insert-mapping (reference)
  ...
  (if 
    (and 
      (findfile (setq NEpath (strcat "Z:\\path\\Mapping\\data\\" symbol "\\" NE))) ;does file exist
      (setq pt (getpoint "\nInsertion point"))
    )
    (progn
      (command "IMAGE" "-point" "_non" pt "-insert" NEpath)
      (setq tif (vlax-ename->vla-object (entlast)))
      (vla-getboundingbox tif'minpt 'maxpt)
      (setq LL (vlax-safearray->list minpt)
            UR (vlax-safearray->list maxpt)
            LR (list (car UR) (cadr LL))
            UL (list (car LL) (cadr UR))
      )
    )
  )
  ;Depending on what image was inserted
  (vla-move tif LR pt) ;move image NW
  (vla-move tif UR pt) ;move image SW
  (vla-move tif LL pt) ;move image NE
  (vla-move tif UL pt) ;move image SE
 ;(princ (strcat NE "\n" NW "\n" SE "\n" SW))
) 

 

The tiff mapping is from Ordinance Survey the free Master Mapping,

how could implement this so it bring in all 4 mapping NE, NW, SE & SW rather than just the NE one alone?

Edited by Charpzy
Posted

I'm unable to find the file every time I try, i have manually attached a tif image into the file and it brings the exact same path as is inside the script
"X:\3. Event TM Plans\Mapping\data\SE\SE80NE.tif"

 

but when I try run the script it always passes the if as a false ending up printing out the NEpath which is "X:\3. Event TM Plans\Mapping\data\SE\SE80NE.tif"

this file is on a server so can be on either drive "X, Y or Z"

(defun JH:insert-mapping (reference)
  (setq NE (strcat (apply 'strcat reference) "NE")
        NW (strcat (apply 'strcat reference) "NW")
        SE (strcat (apply 'strcat reference) "SE")
        SW (strcat (apply 'strcat reference) "SW")
        symbol (substr NE 1 2)
  )

  (if
    (and
      (findfile (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" symbol "\\" NE ".tif")))
      (setq pt (getpoint "\nInsertion point"))
    )
    (progn
      (command "IMAGE" "-point" "_non" pt "-insert" NEpath)
      (setq tif (vlax-ename->vla-object (entlast)))
      (vla-getboundingbox tif 'minpt 'maxpt)
      (setq LL (vlax-safearray->list minpt)
            UR (vlax-safearray->list maxpt)
            LR (list (car UR) (cadr LL))
            UL (list (car LL) (cadr UR))
      )
    )
    (princ NEpath)
  )
  ;Depending on what image was inserted
  (vla-move tif LR pt) ;move image NW
  (vla-move tif UR pt) ;move image SW
  (vla-move tif LL pt) ;move image NE
  (vla-move tif UL pt) ;move image SE
)

 

Posted

Do the tiff's have a second file a geo reference file ? For us it was a JPG and a JGW, we then had a lisp that read the jgw and moved the image to real world co-ordinates.

 

Some Tiff have the real world co-ords buried inside as a property. I had a program that would look inside a graphics program trying to remember its name.

 

Posted

they're only .tif images in the files.

just having a issues with the script trying to locate the file atm, it doesn't recognise the path but manually inserting the image works fine with the exact same path strangely

5 hours ago, BIGAL said:

Do the tiff's have a second file a geo reference file ? For us it was a JPG and a JGW, we then had a lisp that read the jgw and moved the image to real world co-ordinates.

 

Some Tiff have the real world co-ords buried inside as a property. I had a program that would look inside a graphics program trying to remember its name.

 

 

Posted
5 minutes ago, Charpzy said:

just having a issues with the script trying to locate the file atm, it doesn't recognise the path but manually inserting the image works fine with the exact same path strangely

 

 

If you do a princ on NEpath, what is the text string? You could try checking the find file by just entering the filepath with no forumas, see if it works that way

Posted

the NEpath printed the is correct path, i used the exact same path to manually xref the .tif in,
ive also just tried the path as a string with no varibales/ formulas and im getting the same issues.

 

i've checked the path a handful of times to make sure its correct but everytime it cant seem to find the file

36 minutes ago, Steven P said:

 

If you do a princ on NEpath, what is the text string? You could try checking the find file by just entering the filepath with no forumas, see if it works that way

 

  • Like 1
Posted
25 minutes ago, Charpzy said:

the NEpath printed the is correct path, i used the exact same path to manually xref the .tif in,
ive also just tried the path as a string with no varibales/ formulas and im getting the same issues.

 

i've checked the path a handful of times to make sure its correct but everytime it cant seem to find the file

 

 

I only ask because when I try it using a file on my system it works. I don't have 'reference' so by passed that part

 

What does NEpath say, put this in and let us know? If the findfile isn't working break it down to find out where and why.

 

....
  (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" symbol "\\" NE ".tif"))
  (princ "\n")(princ NEpath)
  (if
    (and
      (findfile NEpath)
      (setq pt (getpoint "\nInsertion point"))
    )
    (progn
....

 

 

 

 

Posted

Second part, have you got (command "-image" "-point"....... ) right?

Working through the options on my system (AutoCAD, might be different for other CADs)

(command "-image" "attach" NEpath pt 'scale' 'rotation' )

Posted

i broke the if statement down, it passes past the "true" and goes straight to the "false" part which prints the "NEpath" this prints out:
"X:\3. Event TM Plans\Mapping\data\SE\SE80NE.tif" - which is the correct path

  (if
    (and
      (findfile (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" symbol "\\" NE ".tif")))
      (setq pt (getpoint "\nInsertion point"))
    )
    (progn
      (command "IMAGE" "-point" "_non" pt "-insert" NWpath)
      (setq tif (vlax-ename->vla-object (entlast)))
      (vla-getboundingbox tif 'minpt 'maxpt)
      (setq LL (vlax-safearray->list minpt)
            UR (vlax-safearray->list maxpt)
            LR (list (car UR) (cadr LL))
            UL (list (car LL) (cadr UR))
      )
    )
    (princ NEpath)
  )

 

i've tried writing the path without the formulas same issue, i tried xrefing images into CAD using the exact same printed path and it works fine.

ill keep trying to break the code down, im just so confused with it all and why it can't find the file

15 minutes ago, Steven P said:

 

I only ask because when I try it using a file on my system it works. I don't have 'reference' so by passed that part

 

What does NEpath say, put this in and let us know? If the findfile isn't working break it down to find out where and why.

 

....
  (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" symbol "\\" NE ".tif"))
  (princ "\n")(princ NEpath)
  (if
    (and
      (findfile NEpath)
      (setq pt (getpoint "\nInsertion point"))
    )
    (progn
....

 

 

 

 

 

  • Like 1
Posted

That's odd, it should work. You haven't got any spaces in the file path or not enough (I know you will have tried that), and guess you have copied the file path directly from file manager rather than typing it out when you tried just the file path to stop typing errors.

 

Might be you could try a (getfiled) before and copy the result into your find file line - it has to find it I think - narrowing down where the problem is a little bit at a time

 

 

(setq NEpath (getfiled "Select a TIF File" "X:\\3. Event TM Plans\\Mapping\\data\\" "tif" 8) )

 

Posted

I managed to get it working, it was the "getpoint" and the "and" part in the if statement causing me issues

so i'e changed this part to:

  (if
    (findfile (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" symbol "\\" NE ".tif")))
    (progn
      (command "_IMAGEATTACH" NEpath "G" "E")
    )
  )

 

49 minutes ago, Steven P said:

That's odd, it should work. You haven't got any spaces in the file path or not enough (I know you will have tried that), and guess you have copied the file path directly from file manager rather than typing it out when you tried just the file path to stop typing errors.

 

Might be you could try a (getfiled) before and copy the result into your find file line - it has to find it I think - narrowing down where the problem is a little bit at a time

 

 

(setq NEpath (getfiled "Select a TIF File" "X:\\3. Event TM Plans\\Mapping\\data\\" "tif" 8) )

 

 

but im now having a issue trying to insert at a specific mouse location i've only managed to get it working with using the geo ref as well im having issues trying to get all 4 tif images into the file

  • Like 1
Posted

how about you put the getpoint that you had before before IF, and try (command "_image".... as before?

Posted

it keeps skipping over it, I've tried it in a few places in the script but doesn't actually pop up.

I probably just need a re-write because as it is everything is slung together

 

I don't usually use "commands" so I'm pretty much clueless with them, with other scripts I stick to vla- (probably why im having none stop issues with them haha)

  • Like 1
Posted

Weirdly I am not so good at vla- commands, this works for me though:

 

Comments should show what I tried, need to look at the last part, moving the tif

 

 

(defun JH:insert-mapping (reference)
  (setq NE (strcat (apply 'strcat reference) "NE")
        NW (strcat (apply 'strcat reference) "NW")
        SE (strcat (apply 'strcat reference) "SE")
        SW (strcat (apply 'strcat reference) "SW")
        symbol (substr NE 1 2)
  ) ; end setq

;;(setq NEpath (getfiled "Select a TIF File" "X:\\3. Event TM Plans\\Mapping\\data\\" "tif" 8) ) ;; added in for SP tests
      (setq pt (getpoint "\nInsertion point"))
      (setq scale 1)
      (setq rotation 0)

(if
    (and
      (findfile (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" symbol "\\" NE ".tif")))
;;(findfile NEpath) ;; added in for SP tests
    ) ; end and
    (progn
;;      (command "IMAGE" "-point" "_non" pt "-insert" NEpath) ;; changed this line
(command "-image" "attach" NEpath pt scale rotation)  ;; changed to this line
      (setq tif (vlax-ename->vla-object (entlast)))
      (vla-getboundingbox tif 'minpt 'maxpt)
      (setq LL (vlax-safearray->list minpt)
            UR (vlax-safearray->list maxpt)
            LR (list (car UR) (cadr LL))
            UL (list (car LL) (cadr UR))
      ) ;end setq
    ) ;end progn
    (princ NEpath)
  ) ; end if
  ;Depending on what image was inserted

;  (vla-move tif LR pt) ;move image NW ;; changed this line
(command "move" (entlast) "" LR pt)
;  (vla-move tif UR pt) ;move image SW
;  (vla-move tif LL pt) ;move image NE
;  (vla-move tif UL pt) ;move image SE
)

 

Posted

im using BricsCAD so im getting issues when using anything other than "_IMAGEATTACH",

 

i've added the getpoint line in but it keeps skipping over it like it isnt there, i think its something to do with the dialog not closing once, the "okay" it pressed.

 

all code:

;; Read CSV  -  Lee Mac
;; Parses a CSV file into a matrix list of cell values.
;; csv - [str] filename of CSV file to read

(defun LM:readcsv (csv / des lst sep str)
  (if (setq des (open csv "r"))
    (progn
      (setq sep
        (cond
          ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) ( ",")
        )
      )
      (while (setq str (read-line des))
        (setq lst (cons (LM:csv->lst str sep 0) lst))
      )
      (close des)
    )
  )
  (reverse lst)
)

;; 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 LM:csv-replacequotes (str / pos)
  (setq pos 0)
  (while (setq pos (vl-string-search "\"\"" str pos))
    (setq str (vl-string-subst "\"" "\"\"" str pos)
          pos (1+ pos)
    )
  )
  str
)


(defun JH:insert-mapping (reference)
  (unload_dialog dlg_id)
  (setq NE (strcat (apply 'strcat reference) "NE")
        NW (strcat (apply 'strcat reference) "NW")
        SE (strcat (apply 'strcat reference) "SE")
        SW (strcat (apply 'strcat reference) "SW")
        symbol (substr NE 1 2)
  )
  (setq pt (getpoint "\nInsertion point"))
  (setq scale 5000)
  (setq rotation 0)
  
  
  (if
    (findfile (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" symbol "\\" NE ".tif")))
    (progn
      (command "_IMAGEATTACH" NEpath pt scale rotation)
    )
  )
)


(defun JH:reference-finder (postcode / data)
  (setq upper (strcase postcode)
        lower (strcase postcode T)
        second-char (substr lower 2 2)
        third-char (substr lower 2 2)
        fourth-char (substr lower 2 2)
        num (atoi second-char)
  )

  ;check to see if the second character is a number or not
  (if (= num 1)
    (setq csv-name (substr lower 1 1))
    (setq csv-name (substr lower 1 2))
  )

  (if
    (and
      (setq f (strcat "C:\\BricsCAD Scripts\\MACROS\\CSV\\" (strcase csv-name) ".csv"))
      (setq data (LM:readcsv f))
    )
    (progn
      (if  ;check if string is correctly formatted
        (setq reference (cdr (assoc upper data)))
        (JH:insert-mapping reference)
        (princ "Please enter a valid postcode in the correct format. For example: \"DN15 7PQ\"")
      )
    )
    (princ "Please enter a valid postcode in the correct format. For example: \"DN15 7PQ\"")
  )
  (princ)
)
(princ)


(defun c:POSTCODE ()

  (if (setq fn (findfile "MACROS\\DIALOGS\\POSTCODE.dcl"))
    (setq dlg_id (load_dialog fn))
    (alert "Dialog POSTCODE.dcl not found")
  )

  (new_dialog "PostcodeDia" dlg_id)
  (action_tile "postcode-search" "(JH:reference-finder $VALUE)")
  (start_dialog)
  (princ)
)

 

  • Like 1
Posted (edited)
31 minutes ago, Charpzy said:

i've added the getpoint line in but it keeps skipping over it like it isnt there

 

 

prob need to declare it as a local variable so its nil when you run the lisp and will ask you to define it.

(defun JH:insert-mapping (reference / NE NW SE SW Symbol PT Scale rotaton NEpath)

 

Edited by mhupp
Posted

Ahhh, BricsCAD, why can't you all use the expensive software and not the cheaper, very competent stuff?.....

 

 

What MHUPP says - he uses it

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...