Getting Excelvalue of the next column(s) with one variable.

Getting Excelvalue of the next column(s) with one variable.

Anonymous
Not applicable
1,925 Views
21 Replies
Message 1 of 22

Getting Excelvalue of the next column(s) with one variable.

Anonymous
Not applicable

Hi all,

 

This topic started on this link 

 

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/error-on-getting-a-excelvalue/td-p/54...

 

Short explanation: I m trying to compare a variable with columnvalue's, get from the right match a row, and then use that rownumber to get all the next columns values. 

 

If you look at the link above Henrique put a lisp together for the first columninteger, Now i  m trying to get the next columns, but i keep failing getting a right result. I know that 

(1+ (1+ (vlax-get-property Cell 'Column)))

works for the next column but i can't seem to get it working. 

I tried to made a subfunction val2 to extract from Column C. The Excel table from the link above isn't changed. 

 

;;;                       -----------------------------                   
;;;                       --                         --                   
;;;                       --     Made by Subje       --                   
;;;                       --    Dieter Bevernage     --                   
;;;                       --        Abicon NV        --                   
;;;                       --         Belgium         --                   
;;;                       --                         --                   
;;;                       --    Many Thanks to ->->  --                   
;;;                       --   hmsilva - Henrique    --                   
;;;                       --  <-<-Made it possible   --                   
;;;                       --                         --                   
;;;                       --     Shared wisdom of    --                   
;;;                       --       Afralisp          --                   
;;;                       --      Terry Miller       --                   
;;;                       --        Lee Mac          --                   
;;;                       --        Hallex           --                   
;;;                       --     JefferyPSanders     --                   
;;;                       --                         --                   
;;;                       -----------------------------                   

;;;   Program Name: FindCells 1.01
;;;   First creation on 13/01/2015
;;;   Function: Know the value on Column B and find next the values on the next columns related to previeus value


;;;    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;;;    $$                                                                       $$
;;;    $$          Revision History                                             $$
;;;    $$          Rev  By     Date    Description                              $$
;;;    $$                                                                       $$
;;;    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;;;    $$                                                                       $$
;;;    $$           1    DB   15-01-13   Initial version                        $$
;;;    $$                                                                       $$
;;;    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;;;    $$                                                                       $$
;;;    $$ Overvieuw functions:                                                  $$
;;;    $$                                                                       $$
;;;    $$ rtosr                                                                 $$
;;;    $$ ---Used to change a real number into a short real number string       $$
;;;    $$                                                                       $$
;;;    $$ Exceldossier                                                          $$
;;;    $$ ---Main function                                                      $$
;;;    $$                                                                       $$
;;;    $$ Sel-str                                                               $$
;;;    $$ ---Change type excelvalue                                             $$
;;;    $$                                                                       $$
;;;    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

(defun C:Doss(/ sel-str Exceldossier Val2)  
  
  (vl-load-com)

  (defun sel-str (ExcelValue / rtosr)

;;http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getexcel-lsp-changing-cell-color-of-c...
    (defun rtosr (RealNum~ / DimZin# ShortReal$)
      (setq DimZin# (getvar "DIMZIN")) (setvar "DIMZIN" 8)
      (setq ShortReal$ (rtos RealNum~ 2 8)) (setvar "DIMZIN" DimZin#)
      ShortReal$ );defun rtosr 
      
    (setq ExcelValue
	   (cond
	     ((= (type ExcelValue) 'INT) (itoa ExcelValue))
	     ((= (type ExcelValue) 'REAL) (rtosr ExcelValue))
	     ((= (type ExcelValue) 'STR) (vl-string-trim " " ExcelValue))
	     ((/= (type ExcelValue) 'STR) "")
	     );cond
	  );setq
    )

;;;---Function to find value next to cel with same value as pronounced 
  (defun Exceldossier (ExcelValue / xlfilename sheetName Excelapp xlSheet
    OpenExFile Excelfile MaxRange ExcData Datarange Projectname Column Cell)

;;;---Sheetname 
    (setq sheetName "Dossiergegevens")

;;;---filelocation
    (setq xlfilename "R:\\Autodesk Standards\\test excel\\dossier.xlsx")

;;;---function to start excel
    (setq Excelapp (vlax-get-or-create-object "Excel.Application"))
    
;;;---if no Excel.exe exist errorprompt    
    (if (not Excelapp)
      (progn
	(alert "Can't start Excel")
	(exit)
	)
      )

;;;---Put excel invisible
    (vla-put-visible Excelapp :vlax-false)

;;;---ignore alerts excel
    (vlax-put-property Excelapp 'DisplayAlerts :vlax-False)

;;;---Open file with excel
    (setq Excelfile (vl-catch-all-apply 'vla-open
		      (list (vlax-get-property Excelapp "WorkBooks") xlfileName)))

;;;---look for sheets
    (setq xlSheet (vl-catch-all-apply 'vlax-get-property
		    (list (vlax-get-property Excelfile "Sheets") "Item" sheetName)))

;;;---Make the selected worksheet active
    (vlax-invoke-method xlSheet "Activate")

;;;--- cellrange in sheet
    (setq MaxRange (vlax-get-property (vlax-get-property xlSheet 'Cells) "range" "B2:B20"))
 
 ;; to get the ExcData as a list of strings
    (vlax-for x MaxRange
      (setq ExcData (cons (sel-str (vlax-variant-value (vlax-get-property x 'Value))) ExcData)))
    
    (setq ExcData (reverse ExcData))


 ;; to get the next column cell   Column projectname
    (vlax-for x MaxRange


	(if (= (sel-str (vlax-variant-value (vlax-get-property x 'Value))) ExcelValue)
	  (progn
	    (setq Cell x)
	    (setq Projectname (sel-str (vlax-variant-value
					 (vlax-get-property
					   (vlax-variant-value
					     (vlax-get-property
					       (vlax-get-property xlSheet 'Cells)
					       'Item
					       (vlax-get-property Cell 'Row)
					       (1+ (vlax-get-property Cell 'Column))
					       )
					     )
					   'Value
					   )
					 )
				       )
	      );setq	    
	    cell
	  );progn	  	
	);if
	
	
      );vlax for

;; If cellvalue has no value or existing go to the next errorphrase
    (if Projectname
      Projectname
      (princ "projectname not found!")
      )
    )
  

(defun Val2 (Cell /  Definition)
    
    (setq Definition (sel-str (vlax-variant-value
					 (vlax-get-property
					   (vlax-variant-value
					     (vlax-get-property
					       (vlax-get-property xlSheet 'Cells)
					       'Item
					       (vlax-get-property Cell 'Row)
					       (1+ (1+ (vlax-get-property Cell 'Column)))
					       )
					     )
					   'Value
					   )
					 )
				       )
	  )
    )
  
;;; aks for projectnumber; Get string? 
  (while (/= "" (setq ExcelValue
		       (getstring "\nWhat's the projectnumber? [ Examples: 5020 or VD655 ]:")))
    (setq Projectname (Exceldossier ExcelValue))
    (Setq Definition (Val2 Cell))
    (princ (strcat "\n The value of address " ExcelValue " is: "))
    (princ Projectname )
    (princ Definition )
    )
  (princ) 
  )

 

0 Likes
Accepted solutions (1)
1,926 Views
21 Replies
Replies (21)
Message 2 of 22

hmsilva
Mentor
Mentor

Subje,

 

leave the code as it was, change the command to

 

(defun Doss ( col / sel-str Exceldossier Val2)
;; change this code line
(+ col (vlax-get-property Cell 'Column))


;; define external functions to call the Doss function
;; and as argument 'col' the number
(defun C:Doss1 nil
  (doss 1)
  (princ)
)

  (defun C:Doss2 nil
  (doss 2)
  (princ)
)

Untested... 

 

Henrique

EESignature

0 Likes
Message 3 of 22

hmsilva
Mentor
Mentor

Hi Subje,

 

attached is a code, quickly revised, to demonstrate what I said in my previous post.

 

I hope this helps
Henrique

EESignature

Message 4 of 22

Anonymous
Not applicable

Hi Henrique,

 

Your lsp works great, i did a minor adjustment: 

(defun Doss (col ExcelValue / sel-str xlfilename sheetName Excelapp xlSheet OpenExFile Excelfile MaxRange Datarange cellValue)
(vl-load-com)
  
(defun sel-str (ExcelValue / rtosr)
;;http://forums.autodesk.com/t5/visual-lisp-autolisp?-and-general/getexcel-lsp-changing-cell-color-of-c?...
(defun rtosr (RealNum~ / DimZin# ShortReal$)
  (setq DimZin# (getvar "DIMZIN"))
  (setvar "DIMZIN" 8)
  (setq ShortReal$ (rtos RealNum~ 2 8))
  (setvar "DIMZIN" DimZin#)
  ShortReal$
);defun rtosr     
(setq ExcelValue
(cond
((= (type ExcelValue) 'INT) (itoa ExcelValue))
((= (type ExcelValue) 'REAL) (rtosr ExcelValue))
((= (type ExcelValue) 'STR) (vl-string-trim " " ExcelValue))
((/= (type ExcelValue) 'STR) "")
);cond
);setq
);;sel-str

  ;; Main code
;;;---Function to find value next to cel with same value as pronounced 

;;;---Sheetname 
 (setq sheetName "Dossiergegevens")
;;;---filelocation
 (setq xlfilename "R:\\Autodesk Standards\\test excel\\dossier.xlsx")
;;;---function to start excel
 (setq Excelapp (vlax-get-or-create-object "Excel.Application"))
 (if (not Excelapp)
 (progn
 (alert "Can't start Excel")
 (exit)
 )
 )
;;;---Put excel invisible
 (vla-put-visible Excelapp :vlax-false)
;;;---ignore alerts excel
 (vlax-put-property Excelapp 'DisplayAlerts :vlax-False)
;;;---Open file with excel
 (setq Excelfile (vl-catch-all-apply 'vla-open
 (list (vlax-get-property Excelapp "WorkBooks") xlfileName)))
;;;---look for sheets
 (setq xlSheet (vl-catch-all-apply 'vlax-get-property
 (list (vlax-get-property Excelfile "Sheets") "Item" sheetName)))
;;;---Make the selected worksheet active
 (vlax-invoke-method xlSheet "Activate")
;;;--- cellrange in sheet
 (setq MaxRange (vlax-get-property (vlax-get-property xlSheet 'Cells) "range" "B2:B20"))
;;; aks for projectnumber; Get string? What if he doesn't find a string?
;;; any other ways to search a cell with a property 5009
;;;(setq ExcelValue (getstring "\nWhat's the projectnumber? [ Examples: 5020 or VD655 ]:"))

 ;; to get the next column cell
 (vlax-for x MaxRange
 (if (= (sel-str (vlax-variant-value (vlax-get-property x 'Value))) ExcelValue)
 (setq cellValue (sel-str (vlax-variant-value
 (vlax-get-property
 (vlax-variant-value
 (vlax-get-property
 (vlax-get-property xlSheet 'Cells)
 'Item
 (vlax-get-property x 'Row)
 (+ col (vlax-get-property x 'Column))
 )
 )
 'Value
 )
 )
 )
 )
 )
 )
(if (null cellValue)
(setq cellValue "Value not found!"))
 (princ (strcat "\n The date of this Projectnumber is " ExcelValue " is: "))(princ cellValue)
(setq cellValue nil)

  ;; close, quit and releases VLAobjects
  (vlax-invoke-method Excelfile 'Close)
  (vlax-invoke-method Excelapp 'Quit)
  (mapcar 'vlax-release-object (list Excelapp Excelfile xlSheet MaxRange))
  (repeat 3 (gc))
 
(princ) 
)

;; define external functions to call the Doss function
;; and as argument 'col' next the number to search for


(Defun c:test99 (/ adoc ExcelValue Omschrijving Omschrijving2 Aannemer AdresAannemer Provincie)
  (Setq ExcelValue (getstring "\nWhat's the projectnumber? [ Examples: 5020 or VD655 ]:"))
  (Setq Projectnaam (doss 1 ExcelValue ))
  (Setq Omschrijving (doss 2 ExcelValue ))
  (Setq Omschrijving2 (doss 3 ExcelValue ))
  (Setq Aannemer (doss 4 ExcelValue ))
  (Setq AdresAannemer (doss 5 ExcelValue ))
  (Setq Provincie (doss 6 ExcelValue ))


  (Setq Projectnaam
	 (Def-str Projectnaam))
;;;  	 (Def-str(vlax-variant-value (vlax-get-property Projectnaam 'Value))))
  (Dprops2 Projectnaam)
  (princ) 
)


 

that last row doesn't work, all the rest works. So i m trying to put Variant projectnaam into my custom dwgprops with underlaying Code.

 

The green area works, standalone, but when i try to put variable projectnaam into the function as argument it doesn't reconised it, I think somehow it has to do with the type but i m not sure. That's why i made a second conversion function.

 

 

(defun dProps2 (Projectnaam / dProps dProp) 
   (vl-load-com)
   (setq acadObject (vlax-get-acad-object)) 
   (setq acadDocument (vla-get-ActiveDocument acadObject)) 
   ;;Get the SummaryInfo 
   (setq dProps (vlax-get-Property acadDocument 'SummaryInfo)) 
   ; comment this vla-addCustomInfo if the entries already exist in 
   ; the drawing properties, (which they will after running this one time) 
   
  (vla-SetCustomByIndex dProps 0 "PROJECTNAAM" "wbValue2") 
  (vla-setCustomByKey dProps "PROJECTNAAM" Projectnaam) 
  (vla-getCustomByKey dProps "PROJECTNAAM" 'myValue) 
  (vla-getCustomByIndex dProps 0 'myValue1 'myValue2) 
  (princ (strcat "wbKey value = " myValue "\n")) 
  (princ (strcat "Name = " myValue1 "\n")) 
  (princ (strcat "Value = " myValue2 "\n"))
  (setq Projectnaam nil)
  (princ)  
) 
(defun Def-str (Data / rtosr)
(defun rtosr (RealNum~ / DimZin# ShortReal$)
  (setq DimZin# (getvar "DIMZIN"))
  (setvar "DIMZIN" 8)
  (setq ShortReal$ (rtos RealNum~ 2 8))
  (setvar "DIMZIN" DimZin#)
  ShortReal$
);defun rtosr     
(setq Data
(cond
((= (type Data) 'INT) (itoa Data))
((= (type Data) 'REAL) (rtos Data 2 0))
((= (type Data) 'STR) (vl-string-trim " " Data))
((/= (type Data) 'STR) "")

);cond
);setq
)

 

 

I got as one of the result 

 

Command: TEST99
What's the projectnumber? [ Examples: 5020 or VD655 ]:5008
 The date of this Projectnumber is 5008 is: test8
 The date of this Projectnumber is 5008 is: omschrijving8
 The date of this Projectnumber is 5008 is: betreft8
 The date of this Projectnumber is 5008 is: aannemer8
 The date of this Projectnumber is 5008 is: adres aannemer8
 The date of this Projectnumber is 5008 is: oostvlaanderen; error: lisp value has no coercion to VARIANT with this type:

 So first part of the function good, althought i think if i "setq projectnaam" does it comes with "The date of this Projectnumber is 5008 is:"

That isn't necessary and can come in front the result or can be deleted in the function. I m not sure how to correct this, projectnaam is a symbol and probably doesn't need to change?

 

Thanks Henrique

 

 

0 Likes
Message 5 of 22

Anonymous
Not applicable

 

Little change on the result page:

Also i want to add:

 

if i do In "test99" he change first custom dwgprop to "test", so that works, but when i use Projectnaam it doesn't work. (see previeus post: Dprops is added)

 

(Dprops2 "test")

 

 

(Defun c:test99 (/ adoc ExcelValue Omschrijving Omschrijving2 Aannemer AdresAannemer Provincie)
  (Setq ExcelValue (getstring "\nWhat's the projectnumber? [ Examples: 5020 or VD655 ]:"))
  (prompt "\nThe data of Projectnumber ") (princ ExcelValue) (prompt " is:")
  (prompt "\nProjectnaam: ")(Setq Projectnaam (doss 1 ExcelValue ))
  (prompt "\nOmschrijving: ")(Setq Omschrijving (doss 2 ExcelValue ))
  (prompt "\nOmschrijving2: ")(Setq Omschrijving2 (doss 3 ExcelValue ))
  (prompt "\nAannemer: ")(Setq Aannemer (doss 4 ExcelValue ))
  (prompt "\nAdresAannemer: ")(Setq AdresAannemer (doss 5 ExcelValue ))
  (prompt "\nProvincie: ")(Setq Provincie (doss 6 ExcelValue ))

  (princ)
)

  

main function: 

 

 

(defun Doss (col ExcelValue / sel-str xlfilename sheetName Excelapp xlSheet OpenExFile Excelfile MaxRange Datarange cellValue)
(vl-load-com)
  
(defun sel-str (ExcelValue / rtosr)
;;http://forums.autodesk.com/t5/visual-lisp-autolisp?-and-general/getexcel-lsp-changing-cell-color-of-c?...
(defun rtosr (RealNum~ / DimZin# ShortReal$)
  (setq DimZin# (getvar "DIMZIN"))
  (setvar "DIMZIN" 8)
  (setq ShortReal$ (rtos RealNum~ 2 8))
  (setvar "DIMZIN" DimZin#)
  ShortReal$
);defun rtosr     
(setq ExcelValue
(cond
((= (type ExcelValue) 'INT) (itoa ExcelValue))
((= (type ExcelValue) 'REAL) (rtosr ExcelValue))
((= (type ExcelValue) 'STR) (vl-string-trim " " ExcelValue))
((/= (type ExcelValue) 'STR) "")
);cond
);setq
);;sel-str

  ;; Main code
;;;---Function to find value next to cel with same value as pronounced 

;;;---Sheetname 
 (setq sheetName "Dossiergegevens")
;;;---filelocation
 (setq xlfilename "R:\\Autodesk Standards\\test excel\\dossier.xlsx")
;;;---function to start excel
 (setq Excelapp (vlax-get-or-create-object "Excel.Application"))
 (if (not Excelapp)
 (progn
 (alert "Can't start Excel")
 (exit)
 )
 )
;;;---Put excel invisible
 (vla-put-visible Excelapp :vlax-false)
;;;---ignore alerts excel
 (vlax-put-property Excelapp 'DisplayAlerts :vlax-False)
;;;---Open file with excel
 (setq Excelfile (vl-catch-all-apply 'vla-open
 (list (vlax-get-property Excelapp "WorkBooks") xlfileName)))
;;;---look for sheets
 (setq xlSheet (vl-catch-all-apply 'vlax-get-property
 (list (vlax-get-property Excelfile "Sheets") "Item" sheetName)))
;;;---Make the selected worksheet active
 (vlax-invoke-method xlSheet "Activate")
;;;--- cellrange in sheet
 (setq MaxRange (vlax-get-property (vlax-get-property xlSheet 'Cells) "range" "B2:B20"))
;;; aks for projectnumber; Get string? What if he doesn't find a string?
;;; any other ways to search a cell with a property 5009
;;;(setq ExcelValue (getstring "\nWhat's the projectnumber? [ Examples: 5020 or VD655 ]:"))

 ;; to get the next column cell
 (vlax-for x MaxRange
 (if (= (sel-str (vlax-variant-value (vlax-get-property x 'Value))) ExcelValue)
 (setq cellValue (sel-str (vlax-variant-value
 (vlax-get-property
 (vlax-variant-value
 (vlax-get-property
 (vlax-get-property xlSheet 'Cells)
 'Item
 (vlax-get-property x 'Row)
 (+ col (vlax-get-property x 'Column))
 )
 )
 'Value
 )
 )
 )
 )
 )
 )
(if (null cellValue)
(setq cellValue "Value not found!"))
  (princ cellValue)
(setq cellValue nil)

  ;; close, quit and releases VLAobjects
  (vlax-invoke-method Excelfile 'Close)
  (vlax-invoke-method Excelapp 'Quit)
  (mapcar 'vlax-release-object (list Excelapp Excelfile xlSheet MaxRange))
  (repeat 3 (gc))
 
(princ) 
)

 

result 

 

Command: TEST99
What's the projectnumber? [ Examples: 5020 or VD655 ]:5013
The data of Projectnumber 5013 is:
Projectnaam: test13
Omschrijving: omschrijving13
Omschrijving2: betreft13
Aannemer: aannemer13
AdresAannemer: adres aannemer13
Provincie: limburg
Command:

 

0 Likes
Message 6 of 22

hmsilva
Mentor
Mentor
Subje,

let's see if I understood...

Your goal is:

with one function, get the Projectnumber, Projectnaam, Omschrijving, Omschrijving2, Aannemer, AdresAannemer and Provincie, as prompts at the commandline/Text window.

with another function, set a custom property with the "PROJECTNAAM" value.

Am I correct?

Henrique

EESignature

0 Likes
Message 7 of 22

Anonymous
Not applicable

That first prompt is something handy but not necessary if it blocks something else.

 

We have 2 sorts of drawings: Some concrete part drawings and full concrete plans of each floor. In the part drawing we don't need every attribute but it would be handy if we see a full description of the data of that project. 

 

My primary purpose is indeed getting the data from projectnaam/omschrijving/omschrijving2/aannemer (so each result from a increase from variable "COL") . and put each result in a diffrent customTAB from dwgproperties. We can put those customdwg prop into the template so we don't need to add them with lisp. I m only worried that we only can lisp up to 10 dwgcustom properties, is this true? 

 

Feel free to ask away. 

 

thanks.

0 Likes
Message 8 of 22

hmsilva
Mentor
Mentor

Sorry Subje, but I'm out of the office, later I'll see what I can do...

 

' I m only worried that we only can lisp up to 10 dwgcustom properties, is this true? '

 

Start a new dwg, load and run this demo

 

(vl-load-com)
(defun c:demo ( / a acadDocument acadObject b dProps propKey propValue)
  (setq	acadObject   (vlax-get-acad-object)
	acadDocument (vla-get-ActiveDocument acadObject)
	dProps	     (vlax-get-Property acadDocument 'SummaryInfo)
	a	     -1
	b	     0
  )
  (repeat 20
    (setq a	    (1+ a)
	  b	    (1+ b)
	  propKey   (strcat "PROJECTNAAM-" (itoa b))
	  propValue (strcat "Value" (itoa b))
    )
    (vla-AddCustomInfo dProps propKey propValue)
    (vla-SetCustomByIndex dProps a propKey propValue)
  )
  (command "_.dwgprops")
  (princ)
)

 

 

Henrique

 

EESignature

0 Likes
Message 9 of 22

hmsilva
Mentor
Mentor

Subje,

 

as you have stated:

 

 'We can put those customdwg prop into the template so we don't need to add them with lisp.'

 

if the dwg's have the custom properties Name, setted by Template, you don't need to set the value by Key.

 

To test, setup a testdwg with the "Projectnaam" "Omschrijving" "Omschrijving2" "Aannemer" "AdresAannemer" and  "Provincie" custom properties in it, load the attached code, and type 'demo'.

 

Hope that helps

Henrique

 

EESignature

0 Likes
Message 10 of 22

Anonymous
Not applicable

Hi Henrique,

 

So i already made some changes will update them later, but Already one qeustion popped:

 

When looking for the Value of the customproperties (in that specific file) en then listing them, could it be that he doesn't recognize two words in a value like

 

"Adress Contracter"

 

Or

 

"Description 1"

? i noticed if i put a custom variablename with no spaces (with the same content) that he actually display it. 

 

i Also changed the repeat to 50 times (when looking for values in excel), is that bad? The actual Excel file has like 26 Columns that are used that we will link.

Oh and btw. Works great, everthing goes smooth.

 

Thanks!

0 Likes
Message 11 of 22

hmsilva
Mentor
Mentor

Hi Subje,

 

I'm glad that everthing goes smooth.

 

'When looking for the Value of the customproperties (in that specific file) en then listing them, could it be that he doesn't recognize two words in a value like'

 

Customproperties, Name or Value with spaces in it, are valid strings,

e.g.

_$ (vla-AddCustomInfo suminfo "Test 123 abc" "The prop value")
nil
_$ (vla-AddCustomInfo suminfo "Test 456 def" "The new prop value")
nil
_$ (if (> (setq n (vla-NumCustomInfo suminfo)) 0)
  (repeat n
    (vla-GetCustomByIndex suminfo (setq n (1- n)) 'a 'b)
    (setq PropLst (cons (list n a b) PropLst))
  )
)
((0 "Test 123 abc" "The prop value") (1 "Test 456 def" "The new prop value"))
_$

 

 

Henrique

EESignature

0 Likes
Message 12 of 22

Anonymous
Not applicable

Strange indeed.

 

Maybe it's the way he compare the made list (how you name the index of the columns with a name)  and the list of the custom properties. Is this "space" sensitive?

0 Likes
Message 13 of 22

hmsilva
Mentor
Mentor

Subje,

 

I am out of the office, only tonight I can test it with an excel file.

EDIT:

did test with spaces and the code I did post

DwgProps.png

 

Henrique

EESignature

0 Likes
Message 14 of 22

Anonymous
Not applicable

Henrique,

 

Tried it with multiplay variables and you're right. Now the next problem is, it seems he can't seem to remember the  same values.

Imagine if Projectnaam = DB

and if       Omschrijving = DB

defined in the excel file. 

Could it be that he doesn't fill in the second DB then? 

 

thanks.

0 Likes
Message 15 of 22

hmsilva
Mentor
Mentor

Hi Subje,

 

I did also reproduce that error, later I'll see what I can do.

 

Henrique

EESignature

0 Likes
Message 16 of 22

hmsilva
Mentor
Mentor

Code revised...

 

Henrique

EESignature

0 Likes
Message 17 of 22

Anonymous
Not applicable

henrique,

 

I got a error; He gives two strings

 

Command: DEMO3
; error: bad argument type: stringp ("" "5024")

 

so what's changed untill now, 

  1. i got a prompt of some values, just for test, not finished yet. 

  2. tried to match with dcl. Will attach.

  3. Got more dwgprops. 

 

 

all is attached except dwg.

 

  

0 Likes
Message 18 of 22

Anonymous
Not applicable

Henrique, 

 

Here's a dwg with some customprops.

 

I can't seem to figure this one out. 

Maybe it's that "and" in this part? I trying to understand all pieces now but this one is hard to understand 😄

But probably it's my bad connection wiht dcl 🙂

 

      (foreach x lst
        ;(setq x (nth 2 lst))
        (setq prop (car x))
        (if (and (member prop (mapcar 'cadr proplst))
                 (member prop name)
                 )
          (vla-SetCustomByKey suminfo prop (cadr x))
        )
      )

 

 

Thanks Henrique

0 Likes
Message 19 of 22

hmsilva
Mentor
Mentor

Subje,

the ;(setq x (nth 2 lst)) was only for debugging...

 

Using the 'demo' xls file you did post before, I did change the 'Doss' function, to the output be a list of two elements lists, in order to connect a value to a property name:

Command: (/= "" (setq ExcValue (getstring "\nWhat's the projectnumber? [
Examples: 5020 or VD655 ]:")))
What's the projectnumber? [ Examples: 5020 or VD655 ]:5009
T
Command:
Command: (setq lst (doss ExcValue))
(("Projectnaam" "DB") ("Omschrijving" "DB") ("Omschrijving 2" "betreft9") ("Aannemer" "aannemer9") ("Adres Aannemer" "adres aannemer9")("Provincie" "oostvlaanderen"))


In the 'demo', the
(setq name '("Projectnaam" "Omschrijving" "Omschrijving 2" "Aannemer" "Adres Aannemer" "Provincie"))
is a list with the propertie names to put in the dwg custom properties (you said that in some dwg's you'd not put all properties), only the names in the 'name' list will be written the respective value in custom properties.

(foreach x lst
  ;; set 'prop' with the first elemente from x (property name)
  (setq prop (car x))
  ;; test for member 'prop' in the dwg properties list is
  ;; to ensure the propery exist in dwgprops...
  (if (and (member prop (mapcar 'cadr proplst))
    ;; test if exist in 'name' list
    (member prop name)
      )
    ;; put the value from the second element from x (property value)
    (vla-SetCustomByKey suminfo prop (cadr x))
  )
)

 

At the moment, is not possible to me to see the attachments you have post, but tonight I'll see see what I can do...

 

Henrique

EESignature

Message 20 of 22

hmsilva
Mentor
Mentor
Accepted solution

Hi Subje,

 

attached is a revised code, and a .txt with some explanations.

 

Hope that helps

Henrique

EESignature